5 Replies Latest reply on May 29, 2009 12:22 AM by Arbi Sookazian

    How to turn off validations

    jess singh Newbie

      I need to turn validations off on a form - If i try immediate =true I can bypass validations but I don't see any values in the model bean (e.g Customer bean contained in CustomerAction ).
      How can I get all the values the user entered ? Thanks in Advance.

        • 1. Re: How to turn off validations
          Arbi Sookazian Master

          Are you using the <s:decorate>, <s:validate>, or <s:validateAll> tags or custom validation?


          Why and how long do you need to turn off validation in a particular xhtml?


          Refer to Immediate Components section in Core JSF:



          Immediate input components perform conversion and validation, and subsequently deliver value change events at the beginning of the JSF life cycle - after the Apply Request Values - instead of after Process Validations.

          The example cited for bypassing validation is on pg. 238:


          <h:commandButton value="Cancel" action="cancel" immediate="true"/>


          Validation does not need to occur when you cancel a form.



          If a command has the immediate attribute set, then the command is executed during the Apply Request Values phase.

          Or are you asking for a way to turn off validation for all xhtml pages??

          • 2. Re: How to turn off validations
            jess singh Newbie

            Hi Arbi - thanks for the help, I am using s:validateAll - I need validaton turned off for a particular page - the use case is when user wants to save a record as template (to create new records based on this template later )
            I am aware of 
            <h:commandButton value="Cancel" action="cancel" immediate="true"/>
            but the problem is it does not put any values in the bean - and as you said if it happens after 'apply request values' phase then user entered values should be there but they are not.

            • 3. Re: How to turn off validations
              Arbi Sookazian Master

              jess singh wrote on May 27, 2009 23:16:


              I need validaton turned off for a particular page - the use case is when user wants to save a record as template (to create new records based on this template later )


              So is this always turned off or sometimes turned off depending on what the user is doing on that page?


              There is a big difference.  I imagine the latter.


              I have not encountered a scenario where I must conditionally turn on/off <s:validateAll>.


              There are no attributes for that component according to 2.1 ref doc.


              What kind of validations?  Are they custom business validations (i.e. @Validator)?  Or Hibernate Validator like @NotNull, @Range, @Length, etc.


              Here is an example of business validator:


              @Name("seamValidatorCodes") 
              @Scope(ScopeType.CONVERSATION)
              @org.jboss.seam.annotations.faces.Validator
              public class SeamValidatorCodes implements javax.faces.validator.Validator, java.io.Serializable{...}

              • 4. Re: How to turn off validations
                jess singh Newbie

                Arbi - they are both types - business (custom hibernate validators as well as regular like @NotNull , @Length etc ) - yes s:validateAll can't be turned off through attributes - so what would be my best bet ?

                • 5. Re: How to turn off validations
                  Arbi Sookazian Master

                  The only alternative I can think of is to modify the validateAll tag library and add support method(s) and an attribute to the tag (perhaps enabled?) to add the enable/disable functionality. 


                  ex:


                  <s:validateAll enabled="#{foo.bar}"/>



                  That would be the more elegant solution.  The other workaround is to duplicate the xhtml (one with and one without the s:validateAll tags) and route the requests accordingly depending on enabled or disabled as per the use case requirement.  This is not an optimal solution of course but it may satisfy your requirement(s).