5 Replies Latest reply on Jul 19, 2010 7:45 AM by christine karman

    localeSelector.select()

    christine karman Newbie
      I created a custom localeSelector, and I added localeSelector.select() to make sure the page is updated with the new locale. That didn't work. Then I followed the example in http://seamframework.org/Community/ProblemWithCustomLocaleselector. But still, I need to manually refresh the page to get the page in the right language. If I use the default localeselector in my xhtml file, the page does reload with the new language setting. Is there anything I need to add to make the page refresh?

      This is my code:

      @Name("myLocaleSelector")
      @Scope(ScopeType.SESSION)
      public class MyLocaleSelector {

          @In(value = "userprofile", create = true)
          private Profile profile;

          @In
          private LocaleSelector localeSelector;

          @In
          private ProfileDao profileDao;

          public void select() {
              Locale locale = localeSelector.getLocale();
              if (profile != null) {
                  profile.setLocale(locale);
                  profile.setLanguageCode(locale.getLanguage());
                  profileDao.merge(profile);
              }
              localeSelector.select();
          }
      }


           <h:selectOneMenu value="#{localeSelector.localeString}">
                <f:selectItems value="#{localeSelector.supportedLocales}"/>
                 <a:support event="onchange" action="#{myLocaleSelector.select}"/>
             </h:selectOneMenu>
        • 1. Re: localeSelector.select()
          christine karman Newbie

          Er, I still have this question.

          • 3. Re: localeSelector.select()
            Tim Evers Master

            This has nothing to do with Seam but rather how JSF works.


            You really should take the time to read some more about JSF especially around navigation outcomes to help you understand this particular issue.


            But, for anyone else that comes along and reads this while trying to work out their own problems I will try to give a quick and dirty explanation of what is going on.


            Remember this is a quick and dirty explanation and does not completely reflect how JSF works.


            Essentially before JSF renders a page as html it builds up a component tree we'll call it a View. This View is a tree that describes the page at a component level in a heirachical way. Once this tree is built then the render phase essentially walks down this tree and spits out html.


            This View is NOT discarded after the page is rendered. So, if in the application invoke stage of your next request/post your navigation outcome is NULL or VOID the EXISTING View is used during the render response phase.


            So, even though during your application invoke phase you updated some data that should have changed your web page it wasn't actually updaged because you essentially told JSF to not bother building a new page because your method is a void return type.


            A simple fix to your problem would be to change your method to return a blank String.


                public String select() {
                    Locale locale = localeSelector.getLocale();
                    if (profile != null) {
                        profile.setLocale(locale);
                        profile.setLanguageCode(locale.getLanguage());
                        profileDao.merge(profile);
                    }
                    localeSelector.select();
                    return "";
                }
            



            Doing this should force JSF to build a new page.


            This tutorial mentions the concept. I was looking for a better tutorial but couldn't find it.


            Please remember that this is not exactly how it all works but a simplified explanation.


            Hope it helps you.
            Tim

            • 4. Re: localeSelector.select()
              Tim Evers Master

              I keep thinking I'm forgetting something very important about what I've just said so... If it doesn't work for you let me know. :)


              Something is bugging me about the blank string idea and I can't remember what it is.

              • 5. Re: localeSelector.select()
                christine karman Newbie

                Tim, thank you for the reply...