6 Replies Latest reply on Feb 23, 2010 5:52 PM by willie slepecki

    problem with custom localeselector

    willie slepecki Newbie

      in my code, i need a custom localeselector to drop the cache for a fragment when the locale changes.  i tried using remoting but the localselector system triggers a form submit which causes the remoting to return with an error code 0 every time.


      here is my custom selector



      package com.show.pro.session;
      
      import org.apache.log4j.Logger;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.cache.JbossCacheProvider;
      import org.jboss.seam.international.LocaleSelector;
      
      @Name("showLocaleSelector")
      @Scope(ScopeType.CONVERSATION)
      public class ShowLocaleSelector extends LocaleSelector
      {
           private static final long serialVersionUID = 1L;
           private static Logger logger = Logger.getLogger(ShowLocaleSelector.class);
      
           @In
           protected JbossCacheProvider cacheProvider;
      
           public void selectLanguageKillCSSCache(String language)
           {
                try
                {
                     logger.debug("trying to kill the cache");
                     cacheProvider.remove("cssfragment", "languagebuttons");
                     logger.debug("killed the cache");
                } catch (Exception ex)
                {
                     logger.debug("kill cache died");
                     ex.printStackTrace();
                }
                logger.warn(super.getLanguage());
           }
      }
      


      killing the cache works, my super.getlanguage returns the correct locale, but all my other beans (specifically the ones that handle multi-lingual button images) still return the default locale.  its never changed.  any idea what im missing?

        • 1. Re: problem with custom localeselector
          willie slepecki Newbie

          sorry, this is the line above the logger.warn


          super.selectLanguage(language);



          • 2. Re: problem with custom localeselector
            willie slepecki Newbie

            any ideas on this?  this issue is holding up a rollout to testing, im stumped.

            • 3. Re: problem with custom localeselector
              Thomas Küstermann Newbie

              What about the other beans? How do they use the locale? Maybe it's better to post some code.

              • 4. Re: problem with custom localeselector
                willie slepecki Newbie


                import java.util.Locale;
                @In
                     private Locale locale;
                
                function blka
                returnValue = localButtonRoot + locale.getLanguage() + "/" + showFile;
                return returnValue;
                



                thats all im trying to do, pretty rudimentary but i can't get it to work.  i don't get it.  when i use


                #{localselector.selectlanguage('es')}



                on a command button the the above code works perfectly.  but i need to dump my cache fragments before i switch locals so the urls to all my language sensitive buttons are updated correctly.

                • 5. Re: problem with custom localeselector
                  Thomas Küstermann Newbie

                  You could try to bandy Seams localeSelector with your custom implementation. This should work:


                  import static org.jboss.seam.annotations.Install.APPLICATION;
                  
                  import org.jboss.seam.ScopeType;
                  import org.jboss.seam.annotations.In;
                  import org.jboss.seam.annotations.Install;
                  import org.jboss.seam.annotations.Logger;
                  import org.jboss.seam.annotations.Name;
                  import org.jboss.seam.annotations.Scope;
                  import org.jboss.seam.annotations.intercept.BypassInterceptors;
                  import org.jboss.seam.cache.CacheProvider;
                  import org.jboss.seam.international.LocaleSelector;
                  import org.jboss.seam.log.Log;
                  
                  @Scope(ScopeType.SESSION)
                  @Name("org.jboss.seam.international.localeSelector")
                  @BypassInterceptors
                  @Install(precedence=APPLICATION, classDependencies="javax.faces.context.FacesContext")
                  public class CustomLocaleSelector extends LocaleSelector {
                       private static final long serialVersionUID = 1L;
                  
                       private @In CacheProvider cacheProvider;
                       private @Logger Log logger;
                       
                       private void killCache() {
                            try {
                                 logger.debug("trying to kill the cache");
                                 cacheProvider.remove("cssfragment", "languagebuttons");
                                 logger.debug("killed the cache");
                            } catch (Exception ex) {
                                 logger.debug("kill cache died");
                                 ex.printStackTrace();
                            }
                       }
                       
                       @Override
                       public void select() {
                            killCache();
                            super.select();
                            logger.warn(super.getLanguage());
                       }
                  }
                  



                  You can use this custom localeSelector as usual.

                  • 6. Re: problem with custom localeselector
                    willie slepecki Newbie

                    remove the bypassintercepters and worked perfectly.  thanks a lot, i didn't realize i can overload base seam components like that.  wish i knew that when i was building my authentication system.