在JSF中使用bean验证进行本地化

编程入门 行业动态 更新时间:2024-10-22 22:59:17
本文介绍了在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验证进行本地化

本文发布于:2023-10-27 23:24:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534838.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:JSF   bean

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!