codejitsu
codejitsu

Reputation: 3182

SelectOneMenu changes its value only after the refresh

I use a SelectOneMenu component and a SelectBooleanCheckbox component on my JSF page.

If the combo box is selected, my SelectOneMenu should be blocked and is set to the first element (reset).

Now I have value change listener for combobox implemented and blocking of the SelectOneMenu works very well.

But, when I reset the ComboBox, the SelectOneMenu is set to the old (previous) element.

I think there is something like cache used by JSF.

How do I reset the SelectOneMenu control?

I have linked the value-attribute to the bean property. I set a value for this attribute in the value change listener.

Thanks!

Upvotes: 0

Views: 4077

Answers (1)

BalusC
BalusC

Reputation: 1108722

I'll assume that you're using immediate="true" on the checkbox and that you're calling FacesContext#renderResponse() in your value change listener method (otherwise you would go mad with validations).

In that case, you need to set the value of the dropdown component itself to null as well.

UIInput dropdown = (UIInput) facesContext.getViewRoot().findComponent("formid:dropdownid");
dropdown.setValue(null);

An alternative to UIViewroot#findComponent() is to bind it as bean property.

<h:selectOneMenu binding="#{bean.dropdown}">

Upvotes: 1

Related Questions