Reputation: 1117
I have defined by custom Validator (implements javax.faces.validator.Validator interface and defined in faces-config). I need my custom component to call this validator within my component code ( Renderer class). I want to make my xhtml as clean as possible and don't want to invoke the validator separately in my xhtml by embedding
<f:validator validatorId='xx' />
within my component tag. Just like how I can implement
getConvertedValue(FacesContext context, UIComponent component, Object submittedValue)
within my Renderer to handle conversion, can I do something similar to handle validation within Renderer?
Thanks
Upvotes: 1
Views: 1106
Reputation: 1109635
This is to be done at the UI component level, not at the renderer level. Your custom input component must surely already extend UIInput
, otherwise you've many other (future) problems and/or you'll waste time in writing repeated code. If your custom input component extends UIInput
, then you can just add the Validator
by the inherited UIInput#addValidator()
method in for example the component's constructor.
public MyCustomInputComponent() {
addValidator(new MyCustomValidator());
}
The already-implemented UIInput#validate()
method will do all the conversion, validation and message handling automagically.
Upvotes: 2