我使用JSF 2.0和RichFaces 4创建了一个基于MVC的网站。每个输入文本验证都是使用bean验证注释完成的。我正在使用Hibernate Validator作为bean验证实现。
I made a MVC based website using JSF 2.0 and RichFaces 4. Every input text validation is been done using bean validation annotations. I am using Hibernate Validator as bean validation implementation.
如何显示本地化消息?
如果我使用
@NotNull(message="<h:outputText value=\"#{msg['Mymessage']}\" />")然后它字面上显示< h :outputText value =#{msg ['Mymessage']}/> as message。
then it literally displays <h:outputText value="#{msg['Mymessage']}" /> as message.
这是如何引起的,我该如何解决?
How is this caused and how can I solve it?
推荐答案您应该也不能在邮件中放置JSF标记。此外,JSF自己的资源包不会用于解析本地化验证消息。 JSR303 bean验证是一个与JSF无关的完全独立的API。
You should and can not put JSF tags in the message. Also, JSF's own resource bundle won't be used to resolve localized validation messages. JSR303 bean validation is a completely separate API unrelated to JSF.
要使JSR303 bean验证消息国际化,您需要在类路径根目录中创建一个单独的 ValidationMessages.properties 文件。可以通过 ValidationMessages_xx_XX.properties 文件进行本地化。
To internationalize JSR303 bean validation messages, you need to create a separate ValidationMessages.properties file in the classpath root which can be localized by ValidationMessages_xx_XX.properties files.
例如
ERVNomView=Your message here然后用 {key} 语法。
@NotEmpty(message="{ERVNomView}")参见:
- JSR303规范的第4.3.1.1章
- Chapter 4.3.1.1 of the JSR303 specification
See also:
更多推荐
在JSF中使用bean验证进行本地化
发布评论