How to invoke JSF validator on keyup event?

前端 未结 1 1779
遇见更好的自我
遇见更好的自我 2021-01-23 14:26

I have implemented a JSF validator based on this example.

How can I trigger it on keyup event of ?

I am using JSF 2.0 and Richfaces

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-23 15:23

    You can attach ajax listeners to DOM events on any JSF HTML input component by tag.

    
        
        
    
    
    

    The fooValidator can be just a simple Validator implementation which you register in the faces context by @FacesValidator annotation.

    @FacesValidator("fooValidator")
    public class FooValidator implements Validator {
    
        @Override
        public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
            // ...
    
            if (invalid) {
                throw new ValidatorException(new FacesMessage("Fail!"));
            }
        }
    
    }
    

    See also:

    • Communication in JSF 2 - Ajax validation

    In RichFaces it's not much different. There's only the tag which is basically just on steroids. But it does not really provide additional benefits in this particular case. See also Is there any difference between f:ajax and a4j:ajax?

    0 讨论(0)
提交回复
热议问题