Hi everyone,
I played a little bit with JSR-303 and relative support in Spring...
I wasn't able to have my error codes translated.
My old code was something like:
Code:
public class SignupBeanValidator implements Validator {
public void validate(Object target, Errors errors) {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "empty_field");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "empty_field");
}
}
When validation errors occurred, the relative code (in this exaple, "empty_field") was correctly translated using the correct Locale and the value in my i18n bundle (example "message_en.properties").
Now my code looks like:
Code:
public class SignupBean {
@NotEmpty(message = "empty_field")
private String username;
@NotEmpty(message = "empty_field")
private String password;
}
But I always get the default error String ("may not be empty").
I'm aware that the Hibernate JSR-303 RI looks for ValidationMessages.properties in the root of the classpath, but:
- I don't know how to do Locale resolution. Is this supported by Spring?
- I would like NOT to replicate again my validation error messages, since they are already in my i18n bundles, nicely
Thanks!