PrimeFaces: conditional update on validation

后端 未结 2 972
轮回少年
轮回少年 2021-01-22 06:49

Is it possible to conditionally update JSF components only when validation succeeds?

I would like to be able to do something like



        
2条回答
  •  礼貌的吻别
    2021-01-22 07:37

    The (or PrimeFaces' counterpart ) is intented for this. Or, in your case maybe better, the (or ).

    public void submit() {
        // ...
    
        if (fail) {
            FacesContext.getCurrentInstance().addMessage(null, 
                new FacesMessage(FacesMessage.SEVERITY_ERROR, "Fail", null));
        }
    }
    

    with

    
    
    

    Note that you're as well supposed to use a normal Validator implementation to perform the validation. If it throws a ValidatorException, then the action won't be invoked anyway. Doing validation inside action method is a smell.

提交回复
热议问题