12 Replies Latest reply on Aug 30, 2010 12:52 PM by rodrigo.uchoa

    A @Create method called twice in same conversation

    rodrigo.uchoa

      Hey guys.


      I have an class method annotated with @Create being called two times in a row. It's a scoped conversation component (an action), and it's being created because its corresponding view was rendered.


      In all other xhtml pages I have, the corresponding action classes @create methods are called just once, which for me is the expected behavior.


      Does any one know something that would cause a @create method to be called twice?


      I have put some logging lines inside the @create method, here's the output:



      17:06:23,247 TRACE [ManterFichaOcorrenciaAction] Creating MyAction in Conversation 9. isLongRunning: true
      17:06:23,277 TRACE [ManterFichaOcorrenciaAction] Creating MyAction in Conversation 9. isLongRunning: true



      As you can see the two calls are just few milliseconds apart. I even put some logging in a method annotated with @Destroy, but it's never called.


      Any ideas?

        • 1. Re: A @Create method called twice in same conversation
          cash1981

          Try to put this log info in your create method:





          Conversation.instance().id(); 
          Conversation.instance().isLongRunning();




          My guess is that you do not have a long running conversation on this component, or it is two different conversations.

          • 2. Re: A @Create method called twice in same conversation
            rodrigo.uchoa

            Rodrigo Uchoa wrote on Aug 28, 2010 16:18:



            I have put some logging lines inside the @create method, here's the output:


            17:06:23,247 TRACE [ManterFichaOcorrenciaAction] Creating MyAction in Conversation 9. isLongRunning: true
            17:06:23,277 TRACE [ManterFichaOcorrenciaAction] Creating MyAction in Conversation 9. isLongRunning: true



            As you can see the two calls are just few milliseconds apart. I even put some logging in a method annotated with @Destroy, but it's never called.

            Any ideas?



            I did that already.It's the same long running conversation (read above).

            • 3. Re: A @Create method called twice in same conversation
              cash1981

              And you are sure the scope of the component is CONVERSATION?


              @Scope(ScopeType.CONVERSATION)

              • 4. Re: A @Create method called twice in same conversation
                rodrigo.uchoa

                Hi Shervin,


                Tbanks again for your help.



                Shervin Asgari wrote on Aug 30, 2010 07:00:


                And you are sure the scope of the component is CONVERSATION?

                @Scope(ScopeType.CONVERSATION)



                Yes, I'm sure. It's even listed as a conversation component in seam debug.




                @Name("manterFichaOcorrenciaAction")
                @Scope(ScopeType.CONVERSATION)
                public class ManterFichaOcorrenciaAction extends BaseAction {



                My guess is that something in my xhtml page is triggering the @Create to be called twice. I have to find out 'what' and 'why'. It seems I'm gonna have to debug seam's core to understand when such a thing might happen.

                • 5. Re: A @Create method called twice in same conversation
                  cash1981

                  And what is your BaseAction class?


                  Can also also show the top of that class?

                  • 6. Re: A @Create method called twice in same conversation
                    cash1981

                    Its really much easier to show the relevant part of the codes instead of asking one by one. (Remember for next time)

                    • 7. Re: A @Create method called twice in same conversation
                      rodrigo.uchoa

                      Shervin Asgari wrote on Aug 30, 2010 07:16:


                      Its really much easier to show the relevant part of the codes instead of asking one by one. (Remember for next time)



                      I didn't show before because there's nothing relevant about it. In fact, if I remove the BaseAction class from the inheritance tree, the problem still occurs. BaseAction is not our problem.


                      The only thing left to show is the xhtml page. But it's too big, I don't think it would help.


                      It's also worth mentioning that this pattern, an action class for every page and most of them with @Create methods to do some initialization code, is used throughout our system. And only in this particular case we have this problem.


                      I'm going to change seam's debug level to trace, to see if I find some clues. I'll post afterwards.

                      • 8. Re: A @Create method called twice in same conversation
                        rodrigo.uchoa

                        This is getting interesting.


                        I have created a separate class to listen for the postCreate event of the action I'm having trouble with. Here's the code:


                        @Name("observerTest")
                        @AutoCreate
                        @Scope(ScopeType.CONVERSATION)
                        public class ObserverTest {
                             @Logger
                             private Log logger;
                             
                             
                             @Observer(value = "org.jboss.seam.postCreate.manterFichaOcorrenciaAction", create = true)
                             public void postCreate() {          
                                  logger.trace("manterFichaOcorenciaAction created in Conversation " + Conversation.instance().getId());          
                             }
                        
                        }




                        Now here's the new output:


                        09:02:36,837 TRACE [ManterFichaOcorrenciaAction] Creating manterFichaOcorrenciaAction in Conversation 9. isLongRunning: true
                        09:02:36,872 TRACE [ObserverTest] manterFichaOcorenciaAction created in Conversation 9
                        09:02:36,873 TRACE [ManterFichaOcorrenciaAction] Creating manterFichaOcorrenciaAction in Conversation 9. isLongRunning: true




                        Even though the @Create method is called twice, the postCreate event is just fired once. Weird.

                        • 9. Re: A @Create method called twice in same conversation
                          rodrigo.uchoa

                          I've changed org.jboss.seam.Component's debug level to trace, and as expected, the line


                          09:34:56,208 TRACE [Component] instantiating Seam component: manterFichaOcorrenciaAction



                          ... only appeared once.


                          It's as if something else is calling the create method. Not the Component class.

                          • 10. Re: A @Create method called twice in same conversation
                            rodrigo.uchoa

                            I'm posting here both stack traces each time the @create method gets called. If anyone who knows seam inner workings well enough could point me to the right direction...


                            First one:



                            ManterFichaOcorrenciaAction_$$_javassist_seam_26.construir() line: not available     
                            GeneratedMethodAccessor2126.invoke(Object, Object[]) line: not available     
                            DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25     
                            Method.invoke(Object, Object...) line: 597     
                            Reflections.invoke(Method, Object, Object...) line: 22     
                            Reflections.invokeAndWrap(Method, Object, Object...) line: 144     
                            Component.callComponentMethod(Object, Method, Object...) line: 2249     
                            Component.callCreateMethod(Object) line: 2172     
                            Component.newInstance() line: 2132     
                            Component.getInstance(String, boolean, boolean, Object) line: 2021     
                            Component.getInstance(String, boolean, boolean) line: 1983     
                            Component.getInstance(String, boolean) line: 1977     
                            Namespace.getComponentInstance(String, boolean) line: 55     
                            Namespace.getComponentInstance(String) line: 50     
                            SeamELResolver.resolveBase(ELContext, Object) line: 148     
                            SeamELResolver.getValue(ELContext, Object, Object) line: 51     
                            FacesCompositeELResolver(CompositeELResolver).getValue(ELContext, Object, Object) line: 54     
                            FacesCompositeELResolver.getValue(ELContext, Object, Object) line: 72     
                            AstIdentifier.getValue(EvaluationContext) line: 44     
                            AstValue.getTarget(EvaluationContext) line: 34     
                            AstValue.invoke(EvaluationContext, Class[], Object[]) line: 95     
                            MethodExpressionImpl.invoke(ELContext, Object[]) line: 276     
                            Expressions$2.invoke(Object...) line: 175     
                            Page.preRender(FacesContext) line: 311     
                            Pages.preRender(FacesContext) line: 350     
                            SeamPhaseListener.preRenderPage(FacesContext) line: 561     
                            SeamPhaseListener.beforeRenderResponse(FacesContext) line: 472     
                            SeamPhaseListener.beforeServletPhase(PhaseEvent) line: 148     
                            SeamPhaseListener.beforePhase(PhaseEvent) line: 118     
                            RenderResponsePhase(Phase).handleBeforePhase(FacesContext, ListIterator<PhaseListener>, PhaseEvent) line: 214     
                            RenderResponsePhase(Phase).doPhase(FacesContext, Lifecycle, ListIterator<PhaseListener>) line: 96     
                            LifecycleImpl.render(FacesContext) line: 139     
                            FacesServlet.service(ServletRequest, ServletResponse) line: 266     
                            ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 290     
                            ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 206     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 83     
                            IdentityFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 40     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 69     
                            MultipartFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 90     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 69     
                            ExceptionFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 64     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 69     
                            RedirectFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 45     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 69     
                            ConfigurableXMLFilter(BaseXMLFilter).doXmlFilter(FilterChain, HttpServletRequest, HttpServletResponse) line: 178     
                            Filter(BaseFilter).handleRequest(HttpServletRequest, HttpServletResponse, FilterChain) line: 290     
                            Filter(BaseFilter).processUploadsAndHandleRequest(HttpServletRequest, HttpServletResponse, FilterChain) line: 388     
                            Filter(BaseFilter).doFilter(ServletRequest, ServletResponse, FilterChain) line: 515     
                            Ajax4jsfFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 56     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 69     
                            LoggingFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 60     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 69     
                            HotDeployFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 53     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 69     
                            SeamFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 158     
                            ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 235     
                            ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 206     
                            ReplyHeaderFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 96     
                            ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 235     
                            ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 206     
                            StandardWrapperValve.invoke(Request, Response) line: 235     
                            StandardContextValve.invoke(Request, Response) line: 191     
                            SecurityAssociationValve.invoke(Request, Response) line: 190     
                            BasicAuthenticator(AuthenticatorBase).invoke(Request, Response) line: 433     
                            JaccContextValve.invoke(Request, Response) line: 92     
                            SecurityContextEstablishmentValve.process(Request, Response, HttpEvent) line: 126     
                            SecurityContextEstablishmentValve.invoke(Request, Response) line: 70     
                            StandardHostValve.invoke(Request, Response) line: 127     
                            ErrorReportValve.invoke(Request, Response) line: 102     
                            CachedConnectionValve.invoke(Request, Response) line: 158     
                            StandardEngineValve.invoke(Request, Response) line: 109     
                            CoyoteAdapter.service(Request, Response) line: 330     
                            Http11Processor.process(Socket) line: 829     
                            Http11Protocol$Http11ConnectionHandler.process(Socket) line: 598     
                            JIoEndpoint$Worker.run() line: 447     
                            Thread.run() line: 637






                            Second call:


                            ManterFichaOcorrenciaAction_$$_javassist_seam_26.construir() line: not available     
                            GeneratedMethodAccessor2126.invoke(Object, Object[]) line: not available     
                            DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25     
                            Method.invoke(Object, Object...) line: 597     
                            ReflectionUtil.invokeMethod(Object, Method, Object[]) line: 335     
                            ReflectionUtil.invokeMethod(Object, Object, Object[]) line: 280     
                            AstMethodSuffix.getValue(Object, EvaluationContext) line: 59     
                            AstMethodSuffix.invoke(Object, EvaluationContext, Class[], Object[]) line: 65     
                            AstValue.invoke(EvaluationContext, Class[], Object[]) line: 96     
                            MethodExpressionImpl.invoke(ELContext, Object[]) line: 276     
                            Expressions$2.invoke(Object...) line: 175     
                            Page.preRender(FacesContext) line: 311     
                            Pages.preRender(FacesContext) line: 350     
                            SeamPhaseListener.preRenderPage(FacesContext) line: 561     
                            SeamPhaseListener.beforeRenderResponse(FacesContext) line: 472     
                            SeamPhaseListener.beforeServletPhase(PhaseEvent) line: 148     
                            SeamPhaseListener.beforePhase(PhaseEvent) line: 118     
                            RenderResponsePhase(Phase).handleBeforePhase(FacesContext, ListIterator<PhaseListener>, PhaseEvent) line: 214     
                            RenderResponsePhase(Phase).doPhase(FacesContext, Lifecycle, ListIterator<PhaseListener>) line: 96     
                            LifecycleImpl.render(FacesContext) line: 139     
                            FacesServlet.service(ServletRequest, ServletResponse) line: 266     
                            ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 290     
                            ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 206     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 83     
                            IdentityFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 40     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 69     
                            MultipartFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 90     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 69     
                            ExceptionFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 64     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 69     
                            RedirectFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 45     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 69     
                            ConfigurableXMLFilter(BaseXMLFilter).doXmlFilter(FilterChain, HttpServletRequest, HttpServletResponse) line: 178     
                            Filter(BaseFilter).handleRequest(HttpServletRequest, HttpServletResponse, FilterChain) line: 290     
                            Filter(BaseFilter).processUploadsAndHandleRequest(HttpServletRequest, HttpServletResponse, FilterChain) line: 388     
                            Filter(BaseFilter).doFilter(ServletRequest, ServletResponse, FilterChain) line: 515     
                            Ajax4jsfFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 56     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 69     
                            LoggingFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 60     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 69     
                            HotDeployFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 53     
                            SeamFilter$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 69     
                            SeamFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 158     
                            ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 235     
                            ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 206     
                            ReplyHeaderFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 96     
                            ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 235     
                            ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 206     
                            StandardWrapperValve.invoke(Request, Response) line: 235     
                            StandardContextValve.invoke(Request, Response) line: 191     
                            SecurityAssociationValve.invoke(Request, Response) line: 190     
                            BasicAuthenticator(AuthenticatorBase).invoke(Request, Response) line: 433     
                            JaccContextValve.invoke(Request, Response) line: 92     
                            SecurityContextEstablishmentValve.process(Request, Response, HttpEvent) line: 126     
                            SecurityContextEstablishmentValve.invoke(Request, Response) line: 70     
                            StandardHostValve.invoke(Request, Response) line: 127     
                            ErrorReportValve.invoke(Request, Response) line: 102     
                            CachedConnectionValve.invoke(Request, Response) line: 158     
                            StandardEngineValve.invoke(Request, Response) line: 109     
                            CoyoteAdapter.service(Request, Response) line: 330     
                            Http11Processor.process(Socket) line: 829     
                            Http11Protocol$Http11ConnectionHandler.process(Socket) line: 598     
                            JIoEndpoint$Worker.run() line: 447     
                            Thread.run() line: 637



                            Like I said before, as you can see in the stack trace, something else is triggering the call to the create method in the second time. Not Component.newInstance().


                            • 11. Re: A @Create method called twice in same conversation
                              cash1981

                              It is highly doubtful that this is a bug in Seam. Your code looks correct assuming what you say is correct.


                              There must be somewhere else in your code you are instansiating your component. Try using breakpoints to dig further. Perhaps you have @WebRemote call somewhere. It is impossible by looking at the trace to pin point your problem.

                              • 12. Re: A @Create method called twice in same conversation
                                rodrigo.uchoa

                                Finally got it. Someone put the create method also as a page action in the corresponding page.xml file. That's why it was being called two times.




                                <page xmlns="http://jboss.com/products/seam/pages"
                                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                      xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd">
                                
                                     <action on-postback="false" execute="#{manterFichaOcorrenciaAction.create()}"/>
                                      
                                </page>