注释中消息的GWT验证框架国际化 [英] GWT validation framework internationalization for messages in annotations

查看:109
本文介绍了注释中消息的GWT验证框架国际化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读此页面后,我发现了一种国际化的方式验证消息。这是通过将每种错误类型的翻译放入 ValidationMessages.properties 文件中完成的。

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

这是错误类型特定的,并不是我在我的应用程序中需要的。我需要验证的bean中每个字段的唯一消息。没有国际化可以使用注释完成。

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?

推荐答案

我不知道这是否是答案,因为我没有使用@Pattern,但在文档中,它说@Pattern的消息字段不是文本,而是消息文件的关键字。看这里:

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 ()

默认情况下,message ={javax.validation.constraints.Pattern.message},它看起来像是ValidationMessages.properties文件中的有效键。我想你只需要指定一个自定义键并使用它。

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.

这篇关于注释中消息的GWT验证框架国际化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆