0
votes

I have a small requirement of writing standardized, internationalized javax.validation error messages in this format

@NotNull private String name;

@Max(10) private int age;

Then in this case the error message should prop up as

"The field name is not null"

"The field age is not greater than or equal to 10"

How can I achieve this in a more dynamic way instead of hard-coding the message or variable name inside the annotation.

1

1 Answers

0
votes
@NotNull(message = "{errors.name.missing.msg}")
private String name;

define the value for errors.name.missing.msg in messages.properties (which should be available in your classpath)

You can also make it locale specific by placing it in locale specific property files say in messages_en.properties and messages_fr.properties for i18n.