5 Replies Latest reply on Apr 11, 2007 9:54 AM by pmuir

    Load Resource Bundle

    jbossja

      Hi,

      I'm trying to load a Resource Bundle for a particular Locale.

      In faces-config.xml I have:

       <message-bundle>messages</message-bundle>
       <locale-config>
       <default-locale>fr</default-locale>
       <supported-locale>fr</supported-locale>
       </locale-config>
      


      And in my Bean I load the current Locale in this way:
       LocaleSelector localeSelector = LocaleSelector.instance();
       Locale locale = localeSelector.getLocale();
       ResourceBundle bundle = ResourceBundle.getBundle("messages", locale);
      
      


      I have been able to get the Locale to "fr", but I can't load the Resource Bundle. I get a java.util.MissingResourceException: Can't find bundle for base name messages, locale fr.

      Are there any other configurations that need to be set?

      I have also tried to inject the Resource Bundle using
      @In java.util.ResourceBundle resourceBundle;
      resourceBundle.getBundle("messages").getString(key);
      


      but to no avail

        • 1. Re: Load Resource Bundle

          Hi jbossja

          Do you have a file messages_fr.properties in the directory /resources?

          • 2. Re: Load Resource Bundle

            I typically load Resources like this in my bean class:

            ResourceBundle.instance().getString(this.label);
            


            Attention: ResourceBundle is of type org.jboss.seam.core.ResourceBundle!

            • 3. Re: Load Resource Bundle
              jbossja

              Hi knuwu,

              Yes I do have a messages_fr.properties in my WEB-INF/classes directory.
              I can access the properties file in my jsf pages via <f:loadBundle basename="messages" var="msg"/>.

              The problem is when I'm loading the Resource Bundle in my bean class to populate a drop down list with values that are locale-sensitive.

              I have tried what you suggested but it's not working.

              In my components.xml file I have this:

               <component name="resourceBundle">
               <property name="bundleName">messages</property>
               </component>
              


              Any ideas about what can be done?

              • 4. Re: Load Resource Bundle
                jbossja

                Hi all,

                Can anybody help me with this issue plz?[/img]

                • 5. Re: Load Resource Bundle
                  pmuir

                  resourceBundle.getBundle is a static method on java.util.ResourceBundle. Make sure you have set LocaleSelector.instance().locale to your desired locale and the access it with resourceBundle.getString()