1 Reply Latest reply on Aug 29, 2008 7:26 PM by Guillaume Jeudy

    Using @Length with null values

    David Spindle Newbie

      I am having a bit of trouble using the @Length annotation with a null value.  In my bean I have:

          @Length(min = 4, max = 7)
          public String getSomeVal() {
              return someVal;

      In my seam app, this works as expected and I see the appropriate errors if it is too long or short. The problem is that the field can be null.  When it is, I see this exception in the log:

      javax.el.ELException: org.hibernate.validator.InvalidStateException: validation failed for: org.someapp.model.SomeModel

      What makes it more troubling is that my seam app doesn't seem to get a nice error.  All I see is the JBoss Seam Debug Page with the exception in it.  The exception also does not indicate that there was a problem with the field 'someVal'. 

      So my questions are:

      1. How can I use the @Length annotation with a null value?

      2. How can I get the web app to get a nice error when there is a constraint violation (I was expecting to see some sort of faces message like a normal validation error)?

      Thanks in advance for your help!


        • 1. Re: Using @Length with null values
          Guillaume Jeudy Master

          Have you read Seam doc on this subject ?

          Chapter 9. JSF form validation in Seam

          ..Note: specifying @NotNull on the model does not eliminate the requirement for required="true" to appear on the control! This is due to a limitation of the JSF validation architecture.. 

          If you leave the field blank JSF will not consider it a value change therefore the s:validate tag logic will never get triggered, thats why you get a Seam debug page instead of a nice formatted validation error message.