Using <resource-bundle> files I’m able to have i18n text in my JSF pages.
But is it possible to access these same properties in my managed bean so I can set faces messages with i18n values?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming that you’ve configured it as follows:
If your bean is request scoped, you can just inject the
<resource-bundle>as@ManagedPropertyby its<var>:Or if you just need some specific key:
If your bean is however in a broader scope, then evaluate
#{text}programmatically in method local scope:Or if you only need some specific key:
You can even just get it by the standard
ResourceBundleAPI the same way as JSF itself is already doing under the covers, you’d only need to repeat the base name in code:Or if you’re managing beans by CDI instead of JSF, then you can create a
@Producerfor that:And inject it as below:
Alternatively, if you’re using the
Messagesclass of the JSF utility library OmniFaces, then you can just set its resolver once to let allMessagemethods utilize the bundle.See also the example in the javadoc and the showcase page.