Is it possible to have multiple validators for one input in JSF 2.0? For example, say that I will write a username and the username must have 8 characters. And if OK, then check if the username does not exist in the database.
<ice:inputText id="username" value="#{createClient.username}" maxlength="15">
<-- something like this -->
<f:validator validatorId="usernameValidator" validatorId="usernameExistValidator" />
</ice:inputText>
<ice:message for="username" />
This is absolutely possible. You can attach as many validators to a component as you think is necessary, but you have to use a separate tag for each of them.
E.g.
<ice:inputText id="username" value="#{createClient.username}" maxlength="15">
<f:validator validatorId="usernameValidator"/>
<f:validator validatorId="usernameExistValidator" />
</ice:inputText>
Yes, you can have multiple validators , but in separate < f:validator> tags.
Order of execution is as they are listed on page and execution of each one is not dependent upon the other.
Example:
If username does not have 8 characters, consecutive check if the username exists in the database, will also be executed.
<ice:inputText id="username" value="#{createClient.username}" maxlength="15">
<f:validator validatorId="usernameValidator" />
<f:validator validatorId="usernameExistValidator" />
</ice:inputText>
<ice:message for="username" />
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