5 Replies Latest reply on Jul 19, 2009 5:12 PM by Shervin Asgari

    Begin conversation

    Miloslav Vlach Novice

      Hi,


      I'm working with Seam about 2 years, but whenever I think I have understood the concept of the Conversation I get the error and I'm very confused.


      So, when I'm creating POJO component (not EJB). I would like to have an component with is responsible for managing simple page. This page display some informations and I need to scope this component to CONVERSATION.




          @Create
          @Begin()
          public void init() {
              log.info("nacitam data o instrumentu....: #0", instrumentId);
              try {
                  instrument = (Instrument) em.createQuery("select i from Instrument i where i.id=:id").setParameter("id", instrumentId).getSingleResult();
              } catch (Exception e) {
                  log.error("Nenalezeny instrument: #0, #1", instrumentId, e);
              }
              retOutcome = outcome;
              log.info("Budu se vracet na #0", retOutcome);
              instrumentIdStored = instrumentId;
          }



      So, when I push button Back is performed this code:




          @End(beforeRedirect=true)
          public String back() {
              log.info("vracim: #0", retOutcome);
              return retOutcome;
          }



      When I'm playing with page I have found that cid parameter is still same after clicking button that invoke action back - why ? The End annotation is types correct.
      How can I get the exception



      Caused by: java.lang.IllegalStateException: begin method invoked from a long-running conversation, try using @Begin(join=true) on method: init
      



      When the component exists the @Create method is not invoked. And when don't exist, the new conversation is stared - it is truth ?


      Thanks all.


      Mila

        • 1. Re: Begin conversation
          Shervin Asgari Master

          I think the reason why back here wont kill your component is because you are not performing a redirect. For the conversation to end, a redirect must occur, and maybe this doesnt happen for you here?


          You can however manually leave the conversation. Instead of annotating, try using:




          Conversation.instance().end(); //Flag this conversation for ending
          Conversation.instance().leave(); //Leave this conversation (forces new temporary converation to start



          If this doesnt work, try to force a redirect manually either in pages.xml or with



          Manager.instance().redirect(...)




          • 2. Re: Begin conversation
            Shervin Asgari Master
            <blockquote>
            _Miloslav Vlach wrote on Jul 18, 2009 22:52:_<br/>


            When the component exists the @Create method is not invoked. And when don't exist, the new conversation is stared - it is truth ?

            </blockquote>

            If the component is already in scope, meaning long running conversation, session or application then the @Create method will not be invoked because the component already exsist.
            The long-running conversation is invoked when you get to the @Begin. You can still have a Conversation component, but not long-running. A long-running will be alive until @End or timeout. However a conversation scoped component (not long-running) survives one redirect.


            @ScopeType.EVENT = Goes from Restore View to Render Response, but not redirect
            @ScopeType.CONVERSATION = Goes from Restore VIew to Render Response, and redirect. If long-running conversation, then it spans multiple JSF life cycles.
            @ScopeType.SESSION = Access to session scoped components are serialized
            • 3. Re: Begin conversation
              Shervin Asgari Master

              Sorry formating got lost. Here is with formating



              Miloslav Vlach wrote on Jul 18, 2009 22:52:


              When the component exists the @Create method is not invoked. And when don't exist, the new conversation is stared - it is truth ?



              If the component is already in scope, meaning long running conversation, session or application then the @Create method will not be invoked because the component already exsist.
              The long-running conversation is invoked when you get to the @Begin. You can still have a Conversation component, but not long-running. A long-running will be alive until @End or timeout. However a conversation scoped component (not long-running) survives one redirect.


              @ScopeType.EVENT = Goes from Restore View to Render Response, but not redirect
              @ScopeType.CONVERSATION = Goes from Restore VIew to Render Response, and redirect. If long-running conversation, then it spans multiple JSF life cycles.
              @ScopeType.SESSION = Access to session scoped components are serialized     



              • 4. Re: Begin conversation
                Miloslav Vlach Novice

                I think the reason why back here wont kill your component is because you are not performing a redirect. For the conversation to end, a redirect must occur, and maybe this doesnt happen for you here?

                In .page.xml is for retOutcome redirect... So the redirect is performed.




                If the component is already in scope, meaning long running conversation, session or application then the @Create method will not be invoked because the component already exsist. The long-running conversation is invoked when you get to the @Begin. You can still have a Conversation component, but not long-running. A long-running will be alive until @End or timeout. However a conversation scoped component (not long-running) survives one redirect.


                When I have component for only one page and is Conversation scoped I don't need to use @Begin ? And until the page is accessed the component is live ?
                In many requests ?


                Thanks  you Shervin,


                Mila

                • 5. Re: Begin conversation
                  Shervin Asgari Master

                  Miloslav Vlach wrote on Jul 19, 2009 13:44:


                  When I have component for only one page and is Conversation scoped I don't need to use @Begin ? And until the page is accessed the component is live ?
                  In many requests ?


                  As I said, a conversation scoped component will survive a redirect, and long-running (@Begin) will survive multiple JSF life cycles. So no, if you have a conversation scope you dont need @Begin if it is only for one request and redirect, but if you need for many requests, then you need @Begin.


                  But try to add


                  @Begin(join=true)



                  on your method. That might fix the problem.