struts2 StringLengthFieldValidator annotation not working for empty string

Posted by dcp on Stack Overflow See other posts from Stack Overflow or by dcp
Published on 2010-04-01T13:39:52Z Indexed on 2010/04/01 13:43 UTC
Read the original article Hit count: 453

Filed under:
|
|

Let's say I have this annotation for a struts2 validation:

@StringLengthFieldValidator(key = "key14",
    fieldName = "poNumber", minLength = "1", maxLength = "255",
    message = "poNumber must be between 1 and 255 characters.")
public void setPoNumber(String poNumber) {
    this.poNumber = poNumber;
}

The behavior I'm seeing is that if I pass a string that is empty to this setter, (ex. setPoNumber("")) the validator doesn't catch the error. Strings that are over 255 are caught fine. Equally strange is if I change minLength to 2 and pass a string of length 1, it will catch the error as well. But empty string does not seem to be caught when minLength = "1".

For this reason, I cannot use this validator. I just wondered if I'm doing something wrong. I'm using struts 2.1.8.1.

Thanks for any advice.

© Stack Overflow or respective owner

Related posts about struts2

Related posts about validator