I am learning JSF and need some help in understanding JSF validation. I am trying to do manual, implicit and explicit validation in same page with the help of "http://courses.coreservlets.com/". I wrote 2 input fields with the validaiton as below.
Customer Name: <h:inputText value="#{bean.customerName}" required="true" />
Account No: <h:inputText value ="#{bean.accountNo}" >
<f:validateLength minimum="10"></f:validateLength>
</h:inputText>
<h:commandButton value="Submit" action="#{bean.actionValidate}"></h:commandButton>
<h:messages globalOnly="true"></h:messages>
public String actionValidate(){
FacesMessage fcMessage = new FacesMessage();
if(getAccountNo().isEmpty() || getAccountNo() == null) {
fcMessage.setSummary("account no empty");
fcContext.addMessage(null, fcMessage);
}
if (fcContext.getMessageList().size()>0)
return null;
else
return "ManualValidationResult";
}
My understanding is required attribute of filed 1 and f:validateLength validation will be performed in Process & Validation phase and if the validation fails, the life cycle advances to Render response phase and displays the error message first. once this is passed, the bean validation should be executed - ideally in my example, the validation in the bean will not be executed by any chance. However, I am getting the "Customername - Validation Error: Value is required." if both the fields left blank.
I filled in name field, now I get the "account no empty" message, and later "Validation Error: Length is less than allowable minimum of '5'" if some value is entered in account no field.
Can anyone help me understand the flow please?