2 Replies Latest reply on Jan 27, 2013 9:06 AM by mgvanbochove

    validate-model="false" in someSearchFacelet.page.xml doesn't work?

    mgvanbochove

      Hello Seam 2.3 users,

       

      I'm converting my seam 2.2 application to seam 2.3 and I'm almost finished.

      There's only 1 problem I can't solve yet: disabling jsr 303 bean validation for my search facelets.

       

      Bean validation is great, but for searching to entities you want to reuse your jsr303 annotated pojo's, but without the bean validation:

       

      example:

       

      I want to search for persons by firstName, so I only enter the firstName, without the also required lastName. The search isn't executed, because bean validation says the required field lastName is empty.

       

      There are a lot JSF users with the same problem:

       

      http://stackoverflow.com/questions/5997847/bypass-bean-validation-in-jsf2

      http://stackoverflow.com/questions/7709098/how-to-disable-the-entire-bean-validation-in-jsf?rq=1

      http://stackoverflow.com/questions/12411317/how-to-disable-bean-validation-dynamically

      http://stackoverflow.com/questions/8277816/disable-bean-validation-in-case-of-clearing-resetting-form?rq=1

      http://stackoverflow.com/questions/4852496/jsf-2-0-how-to-skip-jsr-303-bean-validation?rq=1

      http://www.coderanch.com/t/481100/JSF/java/Saving-form-validation

      http://stackoverflow.com/questions/2332713/temoporarily-suppress-beanvalidation-with-jsf

       

      The solutions found in the forums (<f:validateBean disabled="true" />) don't work, because seam adds his own validators.

       

      After spending a lot of time to search for a solution I discovered the validate-model attribute of a page.xml file and the validateModel attribute of a param element inside a page element. I didn't find documentation about this attributes, but I understand it's a way to disable bean validation for some pages which is exactly what I need! Unfortunately the solution doesn't work.

       

      I checked out the seam 2.3 branch from the git repository and started debugging. I found out that the attributes are read correctly from the page.xml files, but it seems like they aren't used in the application.

      This class is always validating the model without looking at the value of the validateModel attribute:

       

      org.jboss.seam.ui.validator.ModelValidator

       

      The jboss-seam project contains this class and method:

       

      org.jboss.seam.navigation.Param.validateConvertedValue(FacesContext facesContext, Object value)

       

      but when setting a breakpoint inside this method I found out the code isn't executed. There is a TODO at line 256 referring to the ModelValidator class.

       

      I've a couple of questions

      1. Is the validate-model attribute and validateModel attribute the way to disable bean validation for some page or param? It looks like a very elegant way to disable builtin validation.
      2. Should f:validateBean disabled="true" work in a seam application
      3. Did I find a bug?

       

      I'm very happy with the new seam 2.3 version and it's important for me I can still use Seam in a JEE6, JSF2 and JPA2 environment and of course with JBoss 7.1.

       

      Many thanks!

       

      Regards,

       

      Marnix van Bochove

        • 1. Re: validate-model="false" in someSearchFacelet.page.xml doesn't work?
          maschmid

          The

          org.jboss.seam.navigation.Param.validateConvertedValue(FacesContext facesContext, Object value) 

           

          is for validating page params, so that is a different thing than validating JSF inputs.

           

          The Seam ModelValidator is not added by default, it is only added by s:validateAll or s:validate. s:validateAll  only adds a seam model validator only if the the JSF one hasn't already been added (e.g. if you use  javax.faces.validator.DISABLE_DEFAULT_BEAN_VALIDATOR ), so, there are these options for using model validators:

           

          A., use the JSF model validator. This is by default for all fields in JSF 2.1

          B. to use the old behavior, set javax.faces.validator.DISABLE_DEFAULT_BEAN_VALIDATOR to disable the default JSF validator and use s:validate or s:validateAll to use Seam model validator as in the Seam2.2 days (except it is now the standard bean validation instead of the old hibernate validation)

          C. Not use any validator on a specific field, but keep using JSF model validator on others: Set f:validateBean disabled="true" on the specific field and not use any of the seam validators (s:validate nor s:validateAll)

           

          The C option however doesn't work due to JSF bug http://java.net/jira/browse/JAVASERVERFACES-2526.

           

          So, to answer your questions:

           

          1. no, it is meant to be used only with page <param>s in pages.xml, to disable validation of params in non-faces requests.

          2. yes, unless you also use s:validateAll or s:validate.

          3. Maybe, I guess you may be hitting http://java.net/jira/browse/JAVASERVERFACES-2526

           

          You can make sure that Seam validator is indeed not used by putting a breakpoint somewhere in jboss-seam-ui org.jboss.seam.ui.validator.ModelValidator validate method. If you still get validation errors but not from the ModelValidator, that means the JSF model validator is used and that is a symptom of JAVASERVERFACES-2526.  If the Seam Validator is used, that can only mean you have s:validateAll in the form.

           

          A possible workaround for that JSF issue is to use set javax.faces.validator.DISABLE_DEFAULT_BEAN_VALIDATOR to true and use either s:validate or f:validateBean on the fields that are meant to be validated (and s:validateAll on the forms which are to be always validated)

          • 2. Re: validate-model="false" in someSearchFacelet.page.xml doesn't work?
            mgvanbochove

            Hi Marek,

             

            Many thanks for your answer! I solved my problem with the info you provided.