Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation annotation and property file

i have a field in my spring bean (managed bean with jsf) and i am validating on it's length with the @Size annotation using JSR303 bean validation as follows:

@Size(min = 7, max = 15, message = "{password.range}")
private String newPassword;

and i was wondering how to read the min and max values from property file, please advise.

like image 989
fresh_dev Avatar asked Feb 28 '12 08:02

fresh_dev


1 Answers

New answer

It is not possible with he standard JSR 303 Validatators. The problem is, that the values in annotations are compile time values, but the values in properties are only available at runtime.

Of course you can write your own JSR-303 Validators that read the value from the properties file while validatation.

So that you can use it this way:

@MySize(minKey = "password.min", maxKey = "password.max", message = "{password.range}")

The MySizeValidator uses the minKey to read that value from a properties file, and then validate the current value.

like image 174
Ralph Avatar answered Oct 18 '22 15:10

Ralph