4 Replies Latest reply on Feb 28, 2007 8:30 PM by tonylmai

    Changing Locale in Seam?

      I have the following code

      public class LocalChanger {
       public String englishAction() {
       FacesContext context = FacesContext.getCurrentInstance();
       context.getViewRoot().setLocale(Locale.ENGLISH);
       return NavigationRuleNames.DISPLAY_SAME_PAGE;
       }
      
       public String otherLangAction() {
       ....
       }
      


      Yet some how when I navigate around, the locale is being set back to the default Locale.

      Is there a better way to do it with Seam?

      Thanks

        • 1. Re: Changing Locale in Seam?
          rmemoria

          Don't use the JSF context. Instead inject the component localeSelector like that:

          @In Locale localeSelector;

          ..
          ..
          ..

          localeSelector.setLocale(Locale.ENGLISH);

          ..
          ..

          It shall work,

          regards,
          Ricardo

          • 2. Re: Changing Locale in Seam?
            rmemoria

            oooppps, my mistake... use this:

            Inject
            @In LocaleSelector localeSelector;

            ..
            set the language
            localeSelector.setLanguage("en");

            • 3. Re: Changing Locale in Seam?

              Seam does make it simpler doesn't it. ;-)

              Coded it. Will test it out as soon as I complete this half baked module that I've been working on all afternoon. 8(

              Thank Ricardo.

              • 4. Re: Changing Locale in Seam?

                I replied before I saw your second posting.

                I like your first code snippet better. That way I can control time and other stuffs. I figured you meant injecting a LocaleSelector so that what I did.

                Here is how I coded it.

                 @In
                 LocaleSelector localeSelector;
                
                 public String englishAction() {
                 localeSelector.setLocale(java.util.Locale.ENGLISH);
                 return NavigationRuleNames.DISPLAY_SAME_PAGE;
                 }
                


                Thanks