Validator with several methods

I have a validator class with a validate() method, I added another method [validate2()] to validate another field. How can I specify in Studio to call the second method?

0 votes

1 answers

1645 views

ANSWER



Hi,

If you're using a standard JSF validator (e.g implementing the interface javax.faces.validator.Validator), it means you're declaring it as a validator to the JSF context and using its identifier to use it inside an input tag, using the “f:validator” tag for instance. Other methods that you could add to this implementation will not be called as they're not part of the Validator interface.

That's why it's much easier to use a standard Seam component, and declare any number of methods that will be used as validation methods, provided you follow the expected signature: “a validator method must be a public method that takes FacesContext, UIComponent, and Object parameters, with a return type of void”.

Once you've done that, in Studio you can reference this method in the “validator” property of the widget where you'd like the validation to occur, using a method binding like “#{mySeamComponent.validate2}” for instance.

0 votes



OK, thanks, I will try with the Seam component.
11/08/2011