Reputation: 2528
So far I only had to build a single java customValidator in my applications. In a current project I'm now facing the necessity to have multiple customValidators I need to register with the application.
Since I can only have one validate
method inside my bean the question arises whether I need to build separate objects for each validation option. Or is there a way to have one common bean containing all the needed validators? But then, what would that look like?
Upvotes: 0
Views: 100
Reputation: 10485
If you are working with a managed bean, you can define your own methods for your validation. The method must have three parameters and return void:
public void validateDemo( FacesContext fc, UIComponent uiCmp, Object toValidate ){
throw new ValidationException( new FacesMessage("Validation error.") );
}
In the XPage you can now use this method in your UIComponent:
<xp:inputText
id="myText"
validator="#{myBean.validateDemo}" />
You can have as many validating methods as you want.
Upvotes: 1