Multiple validators for one input

让人想犯罪 __ 提交于 2019-12-21 12:43:28

问题


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" />

回答1:


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>



回答2:


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" />


来源:https://stackoverflow.com/questions/4980616/multiple-validators-for-one-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!