I have an h:inputText element with more than one validators, eg.:
<h:inputText id="myId" value="#{some.value}">
<f:validator validatorId="validatorOne/>
<f:validator validatorId="validatorTwo/>
</h:inputText>
<h:message for="myId"/>
Now if I implement my validators to throw a ValidatorException, the second validator won’t run, even if it would fail as well.
But I’d like both validators to run and to diplay both error messages in case both validations fail.
I’ve already tried not to throw ValidatorException like this:
facesContext.addMessage(uiComponent.getClientId(), facesMessage);
((UIInput)uiComponent).setValid(false);
But the h:message won’t display both of the error messages, although I can see them if I use h:messages.
How is it possible to display all validation error messages?
That’s the way how JSF validators are specified to work. The validators are fired in the order they’re declared on the component and if one of them fails, then the remnant won’t be fired.
If using
<h:messages>is really not an option for some unclear reason (perhaps you weren’t aware about itsforattribute which works the same way?), then your best bet is creating another validator which in turn delegates to the both validators and merges the caught validator exceptions into one.