struts2 StringLengthFieldValidator annotation not working for empty string
- by dcp
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.