I have this small form and am trying to understand the use of ajax in JSF validation. Here is the form. (The backing bean is just a simple bean with two variables firstName and lastName.)
<h:form>
<h:outputLabel for="firstName" value="First Name: " />
<h:inputText id="firstName" value="#{userBean.firstName}">
<f:validateLength minimum="5" />
<f:ajax event="keyup" render="firstNameMsg" />
</h:inputText>
<h:message id="firstNameMsg" for="firstName" style="color: red" />
<br />
<h:outputLabel for="lastName" value="Last Name: " />
<h:inputText id="lastName" value="#{userBean.lastName}">
<f:validateLength minimum="5" />
<f:ajax event="keyup" render="lastNameMsg" />
</h:inputText>
<h:message id="lastNameMsg" for="lastName" style="color: red" />
<br />
<h:commandButton value="Submit">
<f:ajax execute="firstName lastName" render=":greeting" />
</h:commandButton>
<br />
</h:form>
<h:outputText id="greeting" value="#{userBean.greeting}" />
I have ajax attached to my button which renders the outputText tag with the first name and last name upon submit which is fine. My question is why do I need to use the f:ajax tag with the f:validateLength tag in order to validate the two fields? My understanding is that ajax performs all the lifecycle phases up to the render response phase i.e. it includes validation. Does the validation phase not re render the page with the messages anyway regardless of whether it comes from an ajax request or a regular submit/action request? If I remove the ajax tags attached to the input fields the validation messages don't show up but they do if I remove ajax altogether and just use a regular submit using the commandButtons action event.
Thanks, Alan