Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8930077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:48:11+00:00 2026-06-15T08:48:11+00:00

Using <resource-bundle> files I’m able to have i18n text in my JSF pages. But

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:48:12+00:00Added an answer on June 15, 2026 at 8:48 am

    Assuming that you’ve configured it as follows:

    <resource-bundle>
        <base-name>com.example.i18n.text</base-name>
        <var>text</var>
    </resource-bundle>
    

    If your bean is request scoped, you can just inject the <resource-bundle> as @ManagedProperty by its <var>:

    @ManagedProperty("#{text}")
    private ResourceBundle text;
    
    public void someAction() {
        String someKey = text.getString("some.key");
        // ... 
    }
    

    Or if you just need some specific key:

    @ManagedProperty("#{text['some.key']}")
    private String someKey;
    
    public void someAction() {
        // ... 
    }
    

    If your bean is however in a broader scope, then evaluate #{text} programmatically in method local scope:

    public void someAction() {
        FacesContext context = FacesContext.getCurrentInstance();
        ResourceBundle text = context.getApplication().evaluateExpressionGet(context, "#{text}", ResourceBundle.class);
        String someKey = text.getString("some.key");
        // ... 
    }
    

    Or if you only need some specific key:

    public void someAction() {
        FacesContext context = FacesContext.getCurrentInstance();
        String someKey = context.getApplication().evaluateExpressionGet(context, "#{text['some.key']}", String.class);
        // ... 
    }
    

    You can even just get it by the standard ResourceBundle API the same way as JSF itself is already doing under the covers, you’d only need to repeat the base name in code:

    public void someAction() {
        FacesContext context = FacesContext.getCurrentInstance();
        ResourceBundle text = ResourceBundle.getBundle("com.example.i18n.text", context.getViewRoot().getLocale());
        String someKey = text.getString("some.key");
        // ... 
    }
    

    Or if you’re managing beans by CDI instead of JSF, then you can create a @Producer for that:

    public class BundleProducer {
    
        @Produces
        public PropertyResourceBundle getBundle() {
            FacesContext context = FacesContext.getCurrentInstance();
            return context.getApplication().evaluateExpressionGet(context, "#{text}", PropertyResourceBundle.class);
        }
    
    }
    

    And inject it as below:

    @Inject
    private PropertyResourceBundle text;
    

    Alternatively, if you’re using the Messages class of the JSF utility library OmniFaces, then you can just set its resolver once to let all Message methods utilize the bundle.

    Messages.setResolver(new Messages.Resolver() {
        public String getMessage(String message, Object... params) {
            ResourceBundle bundle = ResourceBundle.getBundle("com.example.i18n.text", Faces.getLocale());
            if (bundle.containsKey(message)) {
                message = bundle.getString(message);
            }
            return MessageFormat.format(message, params);
        }
    });
    

    See also the example in the javadoc and the showcase page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have seen people localize their form using resource. put text data in resource
I have project asp.net with namespace test and I'm using resources (files Resource.resx and
Goal: I want to use jsf`s i18n Scenario: creating resource bundle (utf-8) file info:
I have a large text resource in my bundle. It's a CSV containing lines
I try to get file as resource from bundle jar using Felix/OSGi. I have
I have successfully implemented slider to my Cocos2D project using this resource . The
Using a restful resource in Rails, I would like to be able to insert
I am able to create alternate dictation grammars using the dictation resource kit or
Is it possible to maintain the resource bundle in a folder structure something similar
Using nl.siegmann.epublib I have taken a resource from a book which I try to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.