H: selectOneMenu onchange = "submit ()" instant = "true" does not skip checking for other inputs

I cannot set my h:selectOneMenu without checking other inputs. Here is the code:

 <h:selectOneMenu value="#{a.avalue}" onchange="submit()" immediate="true"> <f:selectItems value="#{b.bvalue}" var="k" itemLabel="#{k.asdad}" itemValue="#{k.asdad}"/> </h:selectOneMenu> <h:inputText id="sada" value="#{c.cvalue}" required="true" requiredMessage="*asdadadadasd" validatorMessage="*asdsadadadadad"> <f:validateLength maximum="80"/> </h:inputText> 

When I change the value of the menu, validators of other inputs are still triggered. How can I deny it?

+7
source share
1 answer

immediate="true" for the current input component does not stop the validators of other input components from triggering. This only leads to the fact that the current input component will be checked one phase earlier than usual. Basically, you need to attach a valueChangeListener to the input component and then call FacesContext#renderResponse() in the listener method so that processing of all other input components is skipped.

But since you already use JSF 2.0, it is much better / easier to use ajax powers instead of this old-fashioned JSF 1.x approach.

eg.

 <h:selectOneMenu value="#{bean.country}"> <f:selectItems value="#{bean.countries}" var="country" itemLabel="#{country.name}" itemValue="#{country.code}"/> <f:ajax listener="#{bean.changeCountry}" /> </h:selectOneMenu> 

from

 public void changeCountry() { System.out.println("Selected country is: " + country); } 

If you want to re-render some parts of the form each time the selection is changed, use the render attribute. For example.

  <f:ajax listener="#{bean.changeCountry}" render="otherComponentId" /> 

See also:

+26
source

All Articles