在JSF中使用bean验证进行本地化 [英] Localization with bean validation in JSF

查看:165
本文介绍了在JSF中使用bean验证进行本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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章

  • See also:

    • Chapter 4.3.1.1 of the JSR303 specification
    • 这篇关于在JSF中使用bean验证进行本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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