2 Replies Latest reply on Sep 19, 2012 9:22 AM by Brent Harlow

    Redraw locale list after logging in

    Brent Harlow
      Hi guys,

      JHeadstart and JHeadstart

      As part of a successful login in my overridden JhsModelServiceImpl createUserContext, I am reading the user's preferred language that is stored in the users DB table and setting the current locale to this value
            String userLocaleStr = userRecord.getLocale();      
            sLog.info("**** FacesContext localeLanguage : " + browserLocale.getLanguage());
            sLog.info("**** Changing to user preferred localeLanguage : " + userLocaleStr);
            userContext.setLocale(new Locale(userLocaleStr));
            LocaleManager.getInstance().setCurrentLocale(new Locale(userLocaleStr));
      My question is - how can I refresh the locale list in the menuGlobal region to display the language choices in the relevant language. I see that with JHeadstart's code, in repsonse to the ValueChangeEvent event, you set the list of supported locales to null and force the region to refresh itself. How can I do that from within my JhsModelServiceImpl class ?

        • 1. Re: Redraw locale list after logging in
          Usually, when you go to a page that requires authentication, you get your login page. On successful authentication, you are then redirected to your original request. If this fits your usecase, then the control will be re-rendered automatically. Depending on how the locales are done, the supporting data controls or bean may need to be refreshed. You may need to just set the current local like you have done. The only thing I can think of is that you are getting a new instance of the locale manager for some reason? You might be able to debug it to find out. You just need to add the source to your project and away you go.

          Interested to hear how you make out.

          1 person found this helpful
          • 2. Re: Redraw locale list after logging in
            Brent Harlow
            Hi Brad,

            I believe the problem is because in the JHeadstart LocaleManager.changeLocale method that is called from the valueChangeEvent, the list of support locales is being cleared - this ensures that on redirection that the current list is repopulated, and this time with the correct language applied to the locale names.

            When I am changing the locale from my createUserContext method I can't call the changeLocale method and am just calling the setCurrentLocale method - which skips the important "this.supportedLocales = null;" line. There is no public setter for the supportedLocales list.

            Got this working by creating my own class extending LocaleManager - overriding getInstance, private list supportedLocales and associated getter/setter methods - then in my createUserContext added
              <managed-bean id="__73">
                <managed-bean-name id="__74">jhsLocaleManager</managed-bean-name>
                <managed-bean-class id="__75">hmdclinical.pulse.controller.jsf.bean.HMDLocaleManager</managed-bean-class>
                <managed-bean-scope id="__76">session</managed-bean-scope>
                  HMDLocaleManager.getInstance().setCurrentLocale(new Locale(userLocaleStr));
            And now it works :) As the supportedLocales is cleared out, when login redirects user to home page, the list is rebuilt in the correct language