Icebreaker
Icebreaker

Reputation: 297

Setting a character limit for a string using Java annotations

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?

Upvotes: 3

Views: 6688

Answers (2)

Icebreaker
Icebreaker

Reputation: 297

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!

Upvotes: 0

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=).

Upvotes: 1

Related Questions