8 Replies Latest reply on Aug 6, 2012 1:08 PM by Ken Finnigan

    Does Seam 3 international honor the browser language?

    John Markakis Newbie

      Hi,

       

      I am trying using to use the seam 3 international module, however it does not seem to take into account the Accept-Language the browser sends.

       

      Is there an easy way to "initialize" the module to the browser preffered language (as JSF does)?

       

      Thanks and sorry if my question is either trivial or foolish.

        • 1. Re: Does Seam 3 international honor the browser language?
          Ken Finnigan Master

          John,

           

          As Seam International is intended to be used with various web frameworks, it doesn't handle changing the user locale directly.

           

          What you can do, either within a filter, or anywhere else where you want to initialize the locale:

           

          @Inject
          @Client
          @Alter
          private Event<java.util.Locale> localeEvent;
          
          public void setUserLocale() {
               localeEvent.fire(Locale.CANADA);
          }
          

           

          setUserLocale() can be in any class that is a CDI Bean in which the Event can be injected into, and all you would need to do is convert the Accept-Language HTTP Header into a Locale to pass into the fire() call.

          • 2. Re: Does Seam 3 international honor the browser language?
            John Markakis Newbie

            Dear John,

             

            Thanks for your advice..

             

            I tried to change the locale right after the session has been created with (LocaleBean as in the Seam 3.1 international-timeanddate example)

             

            @Model
            public class LocaleBean {
            
              @Inject
              @Alter
              @Client
              private Event<Locale> localeEvent;
            
              ....
            
              public void sessionCreated(@Observes @Initialized HttpSession session) {
                localeEvent.fire(FacesContext.getCurrentInstance().getViewRoot().getLocale());
                System.out.println("Initializing session locale to " + FacesContext.getCurrentInstance().getViewRoot().getLocale());
              }
            }
            

             

            but I am getting into some recursion since I get the following error (followed by a few hundred lines of trace):

            Session event listener threw exception: java.lang.StackOverflowError

             

            Since the locale should be initialized for each user session can you think of a good place to do that?

            • 3. Re: Does Seam 3 international honor the browser language?
              Ken Finnigan Master

              I can't think of a reason why that code would result in a recursive loop.

               

              Can you post the stack trace as the overflow error doesn't specify the root cause of the overflow.

              • 4. Re: Does Seam 3 international honor the browser language?
                John Markakis Newbie

                Dear John,

                 

                It continuously repeats the following lines:

                 

                23:39:40,332 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/marka]] (http--127.0.0.1-8080-2) Session event listener threw exception: java.lang.StackOverflowError

                        at java.lang.ClassLoader.defineClass1(Native Method) [:1.6.0_30]

                        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) [:1.6.0_30]

                        at java.lang.ClassLoader.defineClass(ClassLoader.java:615) [:1.6.0_30]

                        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) [:1.6.0_30]

                        at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:397)

                        at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:261)

                        at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:76)

                        at org.jboss.modules.Module.loadModuleClass(Module.java:588)

                        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:183)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:358)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)

                        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:307)

                        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:101)

                        at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:214) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:282) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:265) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:234) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.manager.BeanManagerImpl.notifyObservers(BeanManagerImpl.java:635) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:622) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:616) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.solder.servlet.event.AbstractServletEventBridge.fireEvent(AbstractServletEventBridge.java:45) [solder-impl.jar:]

                        at org.jboss.solder.servlet.event.ServletEventBridgeListener.sessionCreated(ServletEventBridgeListener.java:96) [solder-impl.jar:]

                        at org.apache.catalina.session.StandardSession.tellNew(StandardSession.java:374) [jbossweb-7.0.1.Final.jar:7.0.1.Final]

                        at org.apache.catalina.session.StandardSession.setId(StandardSession.java:344) [jbossweb-7.0.1.Final.jar:7.0.1.Final]

                        at org.apache.catalina.session.ManagerBase.createSession(ManagerBase.java:506) [jbossweb-7.0.1.Final.jar:7.0.1.Final]

                        at org.apache.catalina.session.StandardManager.createSession(StandardManager.java:299) [jbossweb-7.0.1.Final.jar:7.0.1.Final]

                        at org.apache.catalina.connector.Request.doGetSession(Request.java:2665) [jbossweb-7.0.1.Final.jar:7.0.1.Final]

                        at org.apache.catalina.connector.Request.getSession(Request.java:2375) [jbossweb-7.0.1.Final.jar:7.0.1.Final]

                        at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:841) [jbossweb-7.0.1.Final.jar:7.0.1.Final]

                        at org.jboss.weld.context.beanstore.http.LazySessionBeanStore.getSession(LazySessionBeanStore.java:68) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.context.beanstore.http.AbstractSessionBeanStore.setAttribute(AbstractSessionBeanStore.java:72) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.context.beanstore.AttributeBeanStore.put(AttributeBeanStore.java:148) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:126) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:99) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:87) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.seam.international.locale.UserLocaleProducer$Proxy$_$$_WeldClientProxy.changeLocale(UserLocaleProducer$Proxy$_$$_WeldClientProxy.java) [seam-international.jar:]

                        at sun.reflect.GeneratedMethodAccessor42.invoke(Unknown Source) [:1.6.0_30]

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_30]

                        at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_30]

                        at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:305) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:299) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:188) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.introspector.ForwardingWeldMethod.invokeOnInstance(ForwardingWeldMethod.java:59) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:198) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:282) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:265) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:234) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.manager.BeanManagerImpl.notifyObservers(BeanManagerImpl.java:635) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.manager.BeanManagerImpl.fireEvent(BeanManagerImpl.java:628) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at org.jboss.weld.event.EventImpl.fire(EventImpl.java:75) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                        at gr.adev.marka.i18n.ChangeUserLocale.sessionCreated(ChangeUserLocale.java:39) [classes:]

                        at gr.adev.marka.i18n.ChangeUserLocale$Proxy$_$$_WeldClientProxy.sessionCreated(ChangeUserLocale$Proxy$_$$_WeldClientProxy.java) [classes:]

                        at sun.reflect.GeneratedMethodAccessor41.invoke(Unknown Source) [:1.6.0_30]

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_30]

                        at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_30]

                 


                • 5. Re: Does Seam 3 international honor the browser language?
                  John Markakis Newbie

                  After a few days looking around searching it seems I was affected from the WELD-892 issue.

                   

                  I didn't try to update weld in jboss as 7.0.1 instance that I am currently using so I went for the workaround suggested by Ales Justin.

                   

                  So the code that finaly works is:

                   

                  @Model
                  public class LocaleBean {
                  
                      @Inject
                      @Alter
                      @Client
                      private Event<Locale> localeEvent;
                  
                      private boolean handlingSessionInit;
                  
                      .......
                  
                      public void onSessionStartup(@Observes @Initialized HttpSession session) {
                        if (!handlingSessionInit) {
                          handlingSessionInit = true;
                          System.out.println("Changing locale to: " + FacesContext.getCurrentInstance().getViewRoot().getLocale());
                          localeEvent.fire(FacesContext.getCurrentInstance().getViewRoot().getLocale());
                        }
                      }
                  }
                  
                  • 6. Re: Does Seam 3 international honor the browser language?
                    Ken Finnigan Master

                    Glad you were able to find an answer John.

                     

                    You may also want to try the original code in AS 7.1.0.Final to see if that version of Weld has the problem resolved

                    • 7. Re: Does Seam 3 international honor the browser language?
                      John Markakis Newbie

                      I went on and tried the same code it with 7.1.1 and the strangest thing happens.

                       

                      I receive in the response headers two session cookies eg.

                       

                      JSESSIONID=V9+i12zwByxOECy41r5VSmJv.undefined; Path=/marka

                      JSESSIONID=FhBAAYpcGbWsvSzlpSszX-RR.undefined; Path=/marka

                       

                      Any idea what could be causing this behavior?

                      • 8. Re: Does Seam 3 international honor the browser language?
                        Ken Finnigan Master

                        I don't know, as Seam International doesn't set or retrieve cookies of any kind.