GWT validation framework internationalization for messages in annotations

僤鯓⒐⒋嵵緔 提交于 2020-01-15 12:12:40

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/14019777/gwt-validation-framework-internationalization-for-messages-in-annotations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!