How to disable validators using the XSP.partialRefreshPost method?

前端 未结 3 1942
旧时难觅i
旧时难觅i 2020-12-07 04:15

I am using XSP.partialRefreshPost to trigger a partial refresh from client side Javascript. I would like to be able to do the partial refresh without triggering the validato

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-07 04:47

    Here is a PhaseListener which disables the validation if required:

    package ch.hasselba.demo;
    
    import javax.faces.event.PhaseEvent;
    import javax.faces.event.PhaseId;
    import javax.faces.event.PhaseListener;
    import com.ibm.xsp.context.ExternalContextEx;
    import com.ibm.xsp.context.FacesContextExImpl;
    
    public class DisableValidationPhaseListener implements PhaseListener {
    
        private static final long serialVersionUID = 1L;
    
        public void afterPhase(PhaseEvent arg0) {}
    
        public void beforePhase(PhaseEvent arg0) {
            FacesContextExImpl fc  = (FacesContextExImpl) arg0.getFacesContext();
            ExternalContextEx ec = (ExternalContextEx) fc.getExternalContext();
    
            // check for the "disableValidation" parameter & disable validation
            // if required
            if( ec.getRequestParameterMap().containsKey("disableValidation") )
                fc.setDisableValidators(true);
        }
    
        public PhaseId getPhaseId() {
            return PhaseId.PROCESS_VALIDATIONS;
        }
    
    }
    

    You just have to add a parameter to your PartialRefresh, and the validation is disabled:

    XSP.partialRefreshPost('#{id:refreshMe}', {'params': {'disableValidation':true}} );
    

提交回复
热议问题