I want to know the invocation sequence or the flow how the converters and validators will be invoked. I am sharing a sample code for the same:
<f:view>
<h:form>
<h:inputText value="#{myBean.field}">
<f:validateLength minimum="5" maximum="50"></f:validateLength>
<f:validator validatorId="nameValidator" />
</h:inputText>
<br>
<h:inputText id="date" value="#{myBean.date}">
<f:convertDateTime pattern="dd-MMM-yyyy" />
<f:converter converterId="dateConvertor" />
</h:inputText>
<br>
<h:commandButton action="#{myBean.execute}" value="Submit"></h:commandButton>
</h:form>
<h:messages></h:messages>
</f:view>
All UIInput
components (<h:inputText>
and friends) are processed in the same order as they appear in the JSF component tree. During the processing of such a component, first the converter (look, no plural!) is invoked and then the validators are invoked in the same sequence as they have been declared on the component.
In oversimplified Java code, the procedure is roughy like this during validations phase:
for (UIInput input : inputs) {
String id = input.getClientId(context);
Object value = input.getSubmittedValue();
try {
value = input.getConvertedValue(context, value);
for (Validator validator : input.getValidators())
validator.validate(context, input, value);
}
input.setSubmittedValue(null);
input.setValue(value);
} catch (ConverterException | ValidatorException e) {
facesContext.addMessage(id, e.getFacesMessage());
facesContext.validationFailed(); // Skips phases 4+5.
input.setValid(false);
}
}
(you can see the real source code in UIInput#validate()
method)
So, basically, it's in exactly the same order as you see in the XHTML markup. Only on your second input, the second converter has overidden the first converter. An input component can have only one converter. Multiple converters is technically not making any sense.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With