Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<b:selectOneMenu> Ajax response issue #900

Closed
chsreedhar opened this issue Jan 8, 2018 · 3 comments
Closed

<b:selectOneMenu> Ajax response issue #900

chsreedhar opened this issue Jan 8, 2018 · 3 comments

Comments

@chsreedhar
Copy link

chsreedhar commented Jan 8, 2018

View has three <b:selectOneMenu> componets.

    <b:selectOneMenu d="pc" value="#{mcRequestBean.pc}" colMd="9" requiredMessage="Select Primary Category" required="true" labelStyleClass="required-pf" styleClass="selectpicker" process="@this" update="bc" label="Primary Category:" labelColMd="3">
           <f:selectItem itemValue="" itemLabel="--Select --" noSelectionOption="true" />
           <f:selectItems value="#{pCat.primaryCategories}" var="pc" itemLabel="#{pc.id} - #{pc.description}" />
    </b:selectOneMenu>

    <b:selectOneMenu id="bc" value="#{mcRequestBean.bc}" colMd="9" requiredMessage="Select Basic Category" required="true" labelStyleClass="required-pf" styleClass="selectpicker" process="@this" update="stc" label="Basic Category:" labelColMd="3">
       <f:selectItem itemValue="" itemLabel="--Select Basic Category--" noSelectionOption="true" />
       <f:selectItems rendered="#{not empty mcRequestBean.pc}" value="#{bCat.getBasicCategories(mcRequestBean.pc)}" var="bc" itemLabel="#{bc.basicCategory} - #{bc.description}" />
    </b:selectOneMenu>

    <b:selectOneMenu id="stc" value="#{mcRequestBean.stc}" colMd="9" labelStyleClass="required-pf" requiredMessage="Select Shape/Type Category" required="true" styleClass="selectpicker" onchange="ajax:mcRequestBean.prepareCurrent()" label="Shape/Type Category:" labelColMd="3" process="@this" update="pnlGrp, ftr">
        <f:selectItem itemValue="" itemLabel="--Shape/Type Category--" noSelectionOption="true" />
        <f:selectItems rendered="#{not empty mcRequestBean.bc}" value="#{shapeType.geShapeTypeCategories(mcRequestBean.pc.id,mcRequestBean.bc.basicCategory)}" var="sc" itemLabel="#{sc.shapeType} - #{sc.description}" />
    </b:selectOneMenu>

Each updates next one's options through Ajax, initially it works as expected and i can choose options as normally. issue raises if i want to change first or second option, i.e., if i change first #pc option, second one #bcvalue is not setting default.
Browser's response shows there are more than one options having attribute selected="true" in ajax response (file attached issue_selectone.txt)

.

@stephanrauh
Copy link
Collaborator

My gut feeling tells me that's probably not a BootsFaces bug. In particular, the multiple selected options indicate your Category objects don't implement the equals method correctly (or something like that).

I suggest you debug the method SelectOneMenuRenderer.isSelected(). Most likely, you'll see it'll return true too often. This should help you to find out why it does that.

BTW, if I get you right, you expect the second combobox to show the empty default item after selecting a different item in the first combobox. However, I don't see why the second combobox should display something else. Is there some code you didn't show us? In particular, does mcRequestBean.setPc() modify mcRequestBean.bc? I can see the the list of option is updated, but the value as such remains unchanged.

For the sake of convenience, this is the method I suggested to debug:

	private boolean isSelected(FacesContext context, SelectOneMenu menu, Object value, Object itemValue,
			Converter converter) {
		if (itemValue == null && value == null) {
			return true;
		}

		if (value != null) {
			Object compareValue;
			if (converter == null) {
				compareValue = coerceToModelType(context, itemValue, value.getClass());
			} else {
				compareValue = itemValue;

				if (compareValue instanceof String && !(value instanceof String)) {
					compareValue = converter.getAsObject(context, menu, (String) compareValue);
				}
			}

			if (value.equals(compareValue)) {
				return true;
			}

		}
		return false;
	}

@chsreedhar
Copy link
Author

You are right, there were small invisible character entered in equals method. Thanks.

@stephanrauh
Copy link
Collaborator

I suppose that means I can safely close the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants