3 Replies Latest reply on Apr 18, 2012 2:35 AM by Evan Toliopoulos

    Seam's ApplicationBundles ignores the JSF ApplicationWrapper when loading resource bundles

    Evan Toliopoulos Newbie

      Hi,

       

      I am working on a JSF 2 / Seam 3 application where we have provided our own faces ApplicationWrapper class so that we can override the getResourceBundle method because we need to load resources that are XML properties files.

       

      But as we are also using Seam 3 we are trying to leverage Seam's BundleKey way of setting faces messages.

       

      The problem is that Seam 3 has it's own ApplicationBundles class that ignores the standard JSF way of loading a resource bundle:

       

      public ResourceBundle get(final Locale locale, final Object key) {
          containsLocaleMap(locale);
          if (!bundles.get(locale).containsKey(key)) {
              ResourceBundle bundle = ResourceBundle.getBundle(key.toString(), locale);
              put(locale, key.toString(), bundle);
          }
          return bundles.get(locale).get(key);
      }
      

       

      Is this by design or an oversight?

       

      I believe that the line above that reads

       

      ResourceBundle bundle = ResourceBundle.getBundle(key.toString(), locale);
      

       

      should be replaced with something like

       

      FacesContext.getCurrentInstance().getApplication().getResourceBundle(FacesContext.getCurrentInstance(), key.toString());
      

       

      Is this correct or am I missing the point?

       

      Cheers,

      Evan

        • 1. Re: Seam's ApplicationBundles ignores the JSF ApplicationWrapper when loading resource bundles
          Evan Toliopoulos Newbie

          I have worked around the problem by creating a concrete Java resource bundle class that can be passed to Seam's BundleKey:

           

          package com.yourcompany.i18n;
          
          import java.util.Enumeration;
          import java.util.ResourceBundle;
          import javax.faces.context.FacesContext;
          
          public class MessagesResourceBundle extends ResourceBundle {
          
              public MessagesResourceBundle() {
                  final FacesContext facesContext = FacesContext.getCurrentInstance();
                  final ResourceBundle resourceBundle = facesContext.getApplication().getResourceBundle(facesContext, "messages");
                  setParent(resourceBundle);
              }
          
              @Override
              protected Object handleGetObject(String key) {
                  return parent.getObject(key);
              }
          
              @Override
              public Enumeration<String> getKeys() {
                  return parent.getKeys();
              }
          }
          

           

          And to use this, we can do as normal:

           

          new BundleKey("com.yourcompany.i18n.MessagesResourceBundle", "yourMessageKey");
          

           

          It would be nice if Seam 3 just used the standard faces application getResourceBundle method, but in the mean time this will do.

          1 of 1 people found this helpful
          • 2. Re: Seam's ApplicationBundles ignores the JSF ApplicationWrapper when loading resource bundles
            Ken Finnigan Master

            Evan,

             

            The reason that Seam 3 International has a different way to retrieve a ResourceBundle than JSF, is because it does not, and will not, have any dependency on JSF, so that functionality is unavailable to it.

             

            Seam 3 International is view agnostic, so anything that is JSF specific that needs to be built on top of International, should be added to Seam 3 Faces.  I am not certain, but there may already be a way to do this in Seam 3 Faces.

             

            Ken

            1 of 1 people found this helpful
            • 3. Re: Seam's ApplicationBundles ignores the JSF ApplicationWrapper when loading resource bundles
              Evan Toliopoulos Newbie

              Hi Ken,

               

              I'll have a look in the Seam 3 Faces module to see what I can find.

               

              Though, I am now beginning to wonder if the Seam 3 International provides much value over the ordinary JSF messages functionality. It seems a bit clunky.

               

              If I discover anything useful I'll update this thread.

               

              Thanks,

              Evan