問題描述
我使用 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']}"/>
顯示為消息.
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 章
這篇關于在 JSF 中使用 bean 驗證進行本地化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!