Localization with bean validation in JSF

Eildosa picture Eildosa · Jun 6, 2012 · Viewed 7.8k times · Source

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.

How can I display a localized message?

If I use

@NotNull(message="<h:outputText value=\"#{msg['Mymessage']}\" />")

then it literally displays <h:outputText value="#{msg['Mymessage']}" /> as message.

enter image description here

How is this caused and how can I solve it?

Answer

BalusC picture BalusC · Jun 6, 2012

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.

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.

E.g.

ERVNomView=Your message here

Which is then to be specified with {key} syntax.

@NotEmpty(message="{ERVNomView}")

See also: