JSF 2.0 - Ajax Introduces Input Validation

I have a form that needs to be submitted using ajax. I am trying to make validation work, but it does not work when I use ajax. When I exit ajax and submit the form with an empty test version, it starts its validation correctly and does not submit the form. How can I do this with an ajax call. My form is below.

<h:form> <f:ajax> <h:panelGrid columns="3"> <h:outputLable for=test" value="testinput:" /> <h:inputText id=test" required="true" label="testinput" /> <h:message for="test" id="testError"/> </h:panelGrid> <h:commandButton value="Submit" actionListener="#{testBean.doSomething}" /> </f:ajax> </h:form> 
+4
source share
2 answers

<f:ajax> does not re-display the form by default, so you won't see anything. Replace <f:ajax> with <f:ajax execute="@form" render="@form" /> .

+5
source

Maybe try something like this:

 <h:form id="yourFormId"> <!-- form content --> <h:commandButton value="Submit"> <f:ajax execute="yourFormId" listener="#{testBean.doSomething}"/> </h:commandButton> </h:form> 
+3
source

All Articles