Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple validators for one input

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" />
like image 957
kungcc Avatar asked Feb 12 '11 21:02

kungcc


2 Answers

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>
like image 84
Arjan Tijms Avatar answered Oct 10 '22 17:10

Arjan Tijms


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" />
like image 26
ognjenkl Avatar answered Oct 10 '22 18:10

ognjenkl