fresh_dev
fresh_dev

Reputation: 6774

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.

Upvotes: 6

Views: 2599

Answers (1)

Ralph
Ralph

Reputation: 120871

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.

Upvotes: 6

Related Questions