3 Replies Latest reply on Jun 13, 2008 3:30 PM by Guillaume Jeudy

    Order of validations

    Stephen Friedrich Novice

      I am currently migrating an application from Seam 1.0.something to Seam 2.0.2.

      Part of that migration is moving

       @IfInvalid(outcome = Outcome.REDISPLAY) 


      To make that work I had to add required='true' to all my inputText's that previously only had a hibernate validator @Length annotation.

      Now there's something ugly with this:

      1. user leaves field empty and submits

      2. required validator kicks in and says something like cannot be empty

      3. user enters some text foo and submits again

      4. model validator kicks in and says something like must be between 4 and 12 characters

      It is pretty obvious that this is not the most usable.

      Is there a way to make the model validator take precedence over the default required validator, so that the more meaningful message appears right from the start?

        • 1. Re: Order of validations
          hasan Newbie

          You can launch the validation directly on an onblur event. this would show u the error before u submit

          <h:inputText  value="#{myValue}" required="true">
          <a:support event="onblur" reRender="myField, msgZone"/>

          For showing a meaning error, customize it urself

          public String getValue() { return value; }
          public void setValue(String val) { value = val; }

          Hope this helps

          • 2. Re: Order of validations
            Stephen Friedrich Novice

            You misunderstood the question.
            Even if doing validation using ajax, the validator message will be cannot be empty.
            I would like the hibernate model validator be checked before, so that the user gets the more meaningful message must be between 4 and 12 characters.

            • 3. Re: Order of validations
              Guillaume Jeudy Master

              I think you cannot achieve that with JSF. If you don't specify


                and the user enters no values your custom validation will not even kick-in because JSF doesn't take this as a field update.

              In the execution ordering

              required=true (JSF feature)

              will always kick-in before your custom validation.

              If somebody has found a workaround for this I'd be grateful to hear. I'm stuck with the same problem and I believe this is a JSF limitation.