3
votes

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).

1

1 Answers

4
votes

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?