Reputation: 7856
What is the difference between using <h:inputXxx validator>
attribute and <f:validator>
tag?
<h:inputText ... validator="someValidator">
<h:inputText ...>
<f:validator validatorId="someValidator" />
When should I use which one?
Upvotes: 2
Views: 554
Reputation: 1154
Lets assume we have Spring Configs here.
Then in first case "fooValidator" will be one <beanId>
and that respective class(i.e validator class) will be called and validation will happen.
In second case, that should be something like "#{someBean.validationMethod}"
. In this case that validation method will be called.
First one is good approach. Because in that case our validator class extends JSF's default Validator interface and implement validate() method.
Second is good, if you want to customize the validation process.
First will be called at the time of rendering of your page and not sure about second very much. But I think, that is also called at the time of rendering.
Upvotes: 0
Reputation: 1109462
The validator
attribute allows you to reference a standalone managed bean method instead of just the validator ID like so:
<h:inputSomething validator="#{bean.validate}" />
with a validate(FacesContext context, UIComponent component, Object value)
method in the backing bean class without the need for a Validator
implementation.
The <f:validator>
allows you to register multiple validators on the input instead of only one via validator
attribute.
Which one to use depends on the concrete functional requirement. Just choose the one that requires the least amount of code so that you end up in clean code.
Upvotes: 3