Search code examples
jsf-2bean-validation

How to disable the entire bean validation in JSF?


I want to process JSR-303 validation myself, i.e., get validation factory and invoke validate method myself:

class FormBean {
    void saveForm() {
         if (! doValidate()) {
             FacesContext.addMessage(...);
             return;
         }
         ...
     }
     void doValidate() { ... }
 }

Is there any way to disable the bean validation integrated in JSF? (Not that immediate="true", which will not only bypass the validation, but also bypass update-model phases)


Solution

  • You can disable it by disabling the validator for the fields:

    <h:inputText value="#{bean.name}">
      <f:validateBean disabled="true"/>
    </h:inputText>
    

    Update: In order to disable the bean validation for every input field by default, try to set the context variable: javax.faces.validator.DISABLE_DEFAULT_BEAN_VALIDATOR with the value 'true'