7 Replies Latest reply on Mar 14, 2012 11:50 AM by membersound

    Injected locale not the same as getLocale()?

    membersound

      HI,

       

      I have a problem with i18n: after setting the locale to a different language (user selection menu in view), the locale is not updated in "every place".

      More specific: a getLocale() from facesContext does not get the same locale as a directly injected Locale by Jboss Seam. Even though the facesContext is injected by JBoss seam too!!

       

      Maybe I'm missing something here?

      ty

       

       

        @RequestScoped
          class Messages {
              @Inject //injected by jboss seam
              Locale locale;
      
              @Inject //injected by jboss seam
              FacesContext facesContext;
      
              @PostConstruct
              private void init() {
                  System.out.println(facesContext.getViewRoot().getLocale() + ", " + locale);
              }
          }
      
          @RequestScoped
          class Manager {
      
              changeLocale() {
                  Locale locale = new Locale("de");
                  facesContext.getViewRoot().setLocale(locale);
                  new Messages(); //de, de_DE
      
                  locale = new Locale("en");
                  facesContext.getViewRoot().setLocale(locale);
                  new Messages(); //en, de_DE !!
              }
          }
      

       

      There is no problem with basic resource bundle bc I get is like this:

      ResourceBundle.getBundle("/myBundle", facesContext.getViewRoot().getLocale())
      

       

      But now I'm trying to use seam's

      @Inject
      private transient Messages messages;
      

       

      which seems to be based on the Locale locale; I do not get my messages i18n, they always reside in de_DE.