Question

After having read this page I found a way of internationalizing validation messages. It is done by placing translations of each error type into ValidationMessages.properties files.

javax.validation.constraints.Size.message=The property must be between {min} and {max}
javax.validation.constraints.NotNull.message=The property must not be null

It is error type-specific and it's not what I need in my app. I need a unique message for each of my fields in validated beans. With no internationalization it can be done using annotations.

@Pattern(regexp = UiLogicUtils.EMAIL_REGEX, message = "Email is invalid.")
private String requesterEmail;

So how can I make translations of the "Email is invalid" text just for this specific field?

Was it helpful?

Solution

I don't know if this is the answer, because I have not used @Pattern, but in the docs, it says that the message field of the @Pattern is not a text, but a key into the messages file. Look here:

http://docs.oracle.com/javaee/6/api/javax/validation/constraints/Pattern.html#message()

By default message="{javax.validation.constraints.Pattern.message}" which looks like a valid key in ValidationMessages.properties file. I suppose you only have to specify a custom key and use it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top