How to specify a validator for an input component inside a composite component?

后端 未结 3 1199
天命终不由人
天命终不由人 2020-12-06 07:44

Should I register a custom validator in faces-config.xml if I\'m using JSF 2.0.4? My custom validator uses Validator interface which is javax.faces.valida

3条回答
  •  醉酒成梦
    2020-12-06 08:38

    If you are working with JSF 2, I don't think you need to touch the faces-config.xml file to create a customer Validator. You can simply use the annotation @FacesValidator to declare a Validator. It should be something like this:

    @FacesValidator("myValidator")
    public class MyValidator implements Validator {
    
        @Override
        public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
            // Your logic
        }
    
    }
    

    Then you can start using it in your .xhtml page with, for instance, tag:

    
    

提交回复
热议问题