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

  • SEARCH
  • Home
  • 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 1054457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:24:35+00:00 2026-05-16T17:24:35+00:00

I have a properties file for localization: foo=Bar title=Widget Application This is tied in

  • 0

I have a properties file for localization:

foo=Bar
title=Widget Application

This is tied in as a resource-bundle in the faces-config:

<resource-bundle>
    <base-name>com.example.messages.messages</base-name>
    <var>msgs</var>
</resource-bundle>

I can access this just fine in the facelets view using EL:

<title>#{msgs.title}</title>

However, if there are things like SQLExceptions, I need to be able to write messages from the managed bean. This is all working also:

FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "There was an error saving this widget.", null);
FacesContext.getCurrentInstance().addMessage(null, message);

Here is the issue: I want to have those messages come from the properties file so that they, too, can be changed based on the locale. Is there an easy way to access the properties file using injection?

  • 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-05-16T17:24:35+00:00Added an answer on May 16, 2026 at 5:24 pm

    I asked a quite related question on SO:
    How to inject a non-serializable class (like java.util.ResourceBundle) with Weld

    And inside the Seam Forum:
    http://seamframework.org/Community/HowToCreateAnInjectableResourcebundleWithWeld

    To summarize:
    I realized an injectable ResourceBundle with 3 Producers.
    First you need a FacesContextProducer. I took the one from the Seam 3 Alpha sources.

    public class FacesContextProducer {
       @Produces @RequestScoped
       public FacesContext getFacesContext() {
          FacesContext ctx = FacesContext.getCurrentInstance();
          if (ctx == null)
             throw new ContextNotActiveException("FacesContext is not active");
          return ctx;
       }
    }
    

    Then you need a LocaleProducer, which uses the FacesContextProducer. I also took it from Seam 3 Alpha.

    public class FacesLocaleResolver {
       @Inject
       FacesContext facesContext;
    
       public boolean isActive() {
          return (facesContext != null) && (facesContext.getCurrentPhaseId() != null);
       }
    
       @Produces @Faces
       public Locale getLocale() {
          if (facesContext.getViewRoot() != null) 
             return facesContext.getViewRoot().getLocale();
          else
             return facesContext.getApplication().getViewHandler().calculateLocale(facesContext);
       }
    }
    

    Now you have everything to create a ResourceBundleProducer, which can look like this:

    public class ResourceBundleProducer {
      @Inject       
      public Locale locale;
    
      @Inject       
      public FacesContext facesContext;
    
      @Produces
      public ResourceBundle getResourceBundle() {
       return ResourceBundle.getBundle("/messages", facesContext.getViewRoot().getLocale() );
      }
    }
    

    Now you can @Inject the ResourceBundle into your beans. Pay attention that it has to be injected into a transient attribute, otherwise you’ll get an exception complaining that ResourceBundle is not serializable.

    @Named
    public class MyBean {
      @Inject
      private transient ResourceBundle bundle;
    
      public void testMethod() {
        bundle.getString("SPECIFIC_BUNDLE_KEY");
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have properties file config.properties where are stored some application wide properties. And I
The application I have inherited is configured by a properties file passed in with
Assuming I have a .properties file and hibernate.cfg.xml in a standard maven web application
In GWT, you can have a .properties file that lists key value pairs: foo
I have my .properties file in com.someOtherpage -somefolder --theProperties.java `<--- This guy needs it`
I have a properties file in this format attribute1=ó The problem is I need
I have a .properties file, who has this format : toto=titi fofo=fifi coco=cici mama=momo
I have a hibernate.properties file that holds all the hibernate properties for my application.
I have an application that reads a .properties file at start up containing key/values
I have a Spring application-context.xml with PropertyPlaceholderConfigurer to get properties' values from .properties file.

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.