Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localized JSF default validators

Is there any way to painlessly localize the default validator messages in JSF 2.0? I know the key is, i. e., "javax.faces.component.UIInput.REQUIRED", but from all I've found, the only way to change them is in a message-bundle, and it is not locale aware like resource-bundle is. I also didn't find any way to override the default validator for

required="true"

so, is there a way to decently localize those messages without writing a customized "required" validator that uses the needed resource-bundle? Not that it's too much work, but I really like the

required="true"

instead of

<h:inputText ...
    <f:validator  ...
</h:inputText ...

merely for code shortness etc... The question is general, about default messages though, the required validator is mentioned as an example.

JSF 2.0, GFv3.1, JEE6 (Servlets 3.0, EL 2.2, EJB 3.1, etc if that matters to anyone).

like image 376
9 revs Avatar asked Feb 21 '26 12:02

9 revs


1 Answers

How did you conclude that they are not locale aware? It's definitely locale aware. Just provide your own copies of localized messages with keys as definied in chapter 2.5.2.4 of the JSF 2.0 specification and specify the base name of those message resources in <message-bundle> in faces-config.xml. They're loaded by ResourceBundle, you could just adhere the same bundle file naming convention of name_ll_CC.properties where ll is the language code and CC is the (optional) country code.

By the way, I just checked it once again, Mojarra 2.0.3 ships with builtin message bundles in English (default), German, Spanish, French, Japanese, Korean, Portuguese (Brazilian), Chinese and Taiwanese. What language are you using that you can't use one of the builtin message bundles?

like image 140
BalusC Avatar answered Feb 24 '26 05:02

BalusC