2 Replies Latest reply on May 5, 2012 3:31 AM by omidbiz

    Changing a locale when a user is logged in.

    karmats

      Hello everyone!


      I have an application that is pretty much as the default application you get when making a new Seam project in JBoss Developer Studio (a login page and a main page). At the top I have two flags that calls localeSelector.selectLanguage('en') and localeSelector.selectLanguage('no'). In WEB-INF/classes i have messagesen.properties and messagesno.properties.
      Now to my problem. When I click on one of the flags before I login everything works fine, all texts are exchanged and you can change the locale in the main page aswell. However, if I just login and then try to change the locale the texts just comes up as keys.
      I have understood that the locale is user session driven, but is there a way to have this implemented as I want?
      Another thing. If I startup JBoss and change the locale once before I login and then logout and thereafter log back in again with a different user, the locale works fine in the main page aswell. It is however not possible to get the right texts if I once try to change the locale for the first time in the main page (after JBoss have started) then logout and then try to set the locale on the login page. The bundle doesn't seems to be loaded at all.


      Any help is appreciated!

        • 1. Re: Changing a locale when a user is logged in.
          serkan

          Hi,

           

          Did you fix this problem already ? Please let me know, since we're having the same problem.

          • 2. Re: Changing a locale when a user is logged in.
            omidbiz

            I solved this problem by raising an event when user loggedIn

             

             

            @Scope(ScopeType.SESSION)
            @Name("themeLocaleController")
            public class ThemeLocaleController implements Serializable
            {
            
                @In(value = "org.jboss.seam.international.localeSelector")
                LocaleSelector localeSelector;
            
                @In(value = "org.jboss.seam.theme.themeSelector")
                ThemeSelector themeSelector;
            
                @Logger
                private Log log;
            
                @Observer(value=Constants.THEMELOCALE_CHANGER)
                public void changeThemeByLocale()
                {
                    log.info("Changing Theme For " + localeSelector.getLocaleString() + " Locale");
                    localeSelector.select();
                    if (localeSelector.getLocaleString().equalsIgnoreCase("fa"))
                    {
                        themeSelector.setTheme("persianTheme");
                    }
                    else
                    {
                        themeSelector.setTheme("defaultTheme");
                    }
                    themeSelector.select();
            
                }
            
            }