3

I'm trying to create a string with a character length restriction of 12 for my JBOSS Seam project. The string must either be 12 characters or blank. My length annotation is correct which is the following:

    @Length(min = 12,max = 12)

However when I try to put a null value in there I get an InvalidStateException: validation fail error. Any ideas how to allow this?

Icebreaker
  • 277
  • 1
  • 6
  • 13

2 Answers2

1

Null value for String and empty String are not the same thing. You are passing a null value (not a String of length 0). Check this out:

Difference between null and empty ("") Java String

Also, you should try out @Size(min=,max=).

Community
  • 1
  • 1
  • The size part isn't the issue. It correctly allows only 12 characters and anything less or more will produce a warning. It's the null scenario that gets the error. – Icebreaker Jul 03 '13 at 16:17
  • Need sugestion, how do I apply check of Integer only using @Size? Does hibernate provide any such Annotation allowing combination of maxLength and numbersOnly? – Pratik Ambani Aug 11 '17 at 11:08
0

Well I decided to not rely on the @Length annotation and instead created my own custom validator class to do the job and that worked out well. Thanks anyway!

Icebreaker
  • 277
  • 1
  • 6
  • 13