• Post Reply Bookmark Topic Watch Topic
  • New Topic

precedence of validators specified for h:inputText  RSS feed

 
Ranch Hand
Posts: 1647
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, in JSF, what if we specify two validators for an input text?


The JSF specification does not mention this.
 
Saloon Keeper
Posts: 19272
85
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A validator works by throwing a ValidationException. So my logical conclusion is that if you have multiple validators applied to one item they'd all get added to the component tree and all get invoked (although you should not assume any particular order of execution). If and ONLY if all validators are happy (don't throw exception), then the field passes.

If more than one validator would throw an Exception, then it MIGHT be the case that each exception is logged to the JSF messages queue - meaning that every validator is invoked and processed in its own error context instead of the less-friendly one-strike/you're out alternative. But then again, it might not.

According to me in an earlier question of this type, JSF was definitely set up to handle what you are asking about, even if the exact details haven't been spelled out.

Regardless, if you write a validator, it should neither maintain state or have side-effects. All it should do is check for validity and throw an exception if the check fails.

 
Himai Minh
Ranch Hand
Posts: 1647
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Tim. Thanks for your response.
I also find an example saying that one component can have multiple validators:https://stackoverflow.com/questions/4980616/multiple-validators-for-one-input
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!