3 Replies Latest reply on May 26, 2008 11:09 PM by stephen

    2 Phase Validation Scenario

    graben

      I have you little problem with validation checking. I use Hibernate Validation for simple checks and native checking in EJB with FacesMessage for more complex scenarios. This combination results in feeled 2 phase validation process.


      1. Phase:
      In the first phase the hibernate validators are checked and messages are printed to view.


      2. Phase:
      After successfully committed through hibernate validations the business validations are fired.


      This behaviour is quite odd since the user first thinks everything is alright and than will get another list of errors/problems.


      Any thoughts about that? I explicitly dont't want to solve every validation with hibernate since it is often scenario dependent.

        • 1. Re: 2 Phase Validation Scenario
          stephen

          1. Phase: In the first phase the hibernate validators

          That's not quite correct. All validators are checked in that phase.
          You can execute your own validations in that phase, too.
          See sections 10 and 29.2 in the latest version of the seam reference. (And google for jsf validation.)

          • 2. Re: 2 Phase Validation Scenario
            graben

            Well, that's not really what I mean. Sometimes you need the content of several fields to check for some rules. So I can't use @Validator which is meant for single fields only.

            • 3. Re: 2 Phase Validation Scenario
              stephen

              Ah I see. Yes, validation of interdependent fields is a weak point of JSF.
              Still, I think you should use a JSF validator.
              A common way to do this is to attach the validator to the last component. Inside the validator find the other fields by looking them up from the component tree, then use their local values.
              (Or use binding to get access to the other components, but be aware that you can't bind jsf components to a seam component in conversation scope.)


              (Or use an artificial hidden field with a fixed value and access all fields you need to validate by using the component tree/binding.)



              Core Java Server Faces has a nice section on this.