5 Replies Latest reply on Sep 5, 2013 8:58 AM by wangliyu

    Conversations... Ending and Starting a new conversation in another controller.

    tony.herstell1

      [The "CRUD" bean...]

      I am "leaving" a bean (and conversation) via:

       public String back() {
            this.logger.info(">>>Back");
            finishMyConversation();
            this.logger.info("<<<Back");
            return this.actionManagementController.init();
         }
      

       

      (In parent class...)

         protected void finishMyConversation() {
            if (!this.getConversation().isTransient()) { // May have been an error (don't
               // get trapped on the page).
               this.getConversation().end(); // END THE LONG RUNNING CONVERSATION
            }
         }
      

       

      [The "Manage The List" bean...]

      The call to actionManagementController.init (in another @Injected bean) is, now, starting a new conversation

         // land here off a menu click...
         public String init() {
            this.logger.info(">>>init");
            startMyConversation();
            setShowIds(false);
            this.logger.info("<<<init");
            return "pretty:manageActions";
         }
      

       

      (In parent class...)

       protected void startMyConversation() {
            // Start a Conversation
            if (!this.getConversation().isTransient()) {
               this.getConversation().end();
            }
            this.getConversation().begin(); // START THE LONG RUNNING CONVERSATION
         }
      

       

      What I see happening is the conversation seems to be carried on...

       

      I don't see any side-effects (yet) but is there a way to "really" end a conversation and force a new one to be started?

       

      I originally had this done the Seam 2 way...  that one bean was Sessions scoped and contained a list of "things" to "do stuff to" (like the hotel example in Seam2)... This would launch into the other bean and start a conversation to "do stuff" to the thing you had picked... This initially seemed to work fine, but then I kept getting problems as the sessions bean was coming up with "old" versions of the objects (from a bit of reading its a "feature" of Hibernate).

        • 1. Re: Conversations... Ending and Starting a new conversation in another controller.
          luksa

          Calling .end() on a conversation doesn't actually end or destroy it. It only changes the conversation from long-running to transient. The conversation is destroyed at the end of the request (if it is transient at that time). This means that calling .end() and then immediately begin() on a conversation doesn't actually do anything.

           

          So to answer your question: it's not possible to destroy and then create a new conversation in the same request. You'd have to split this among two requests (the first request ends the conversation and then redirects to another view, passing data to it, and the other view then starts a new conversation)

          1 of 1 people found this helpful
          • 2. Re: Conversations... Ending and Starting a new conversation in another controller.
            tony.herstell1

            Well that's going to be a problem based on the use Case...

            Give a finish what I am doing button and then a go back to the list of "stuff" button is not going to wash...

            Shame about Hibernate as the correct way was the way I had it... Session for list of stuff and a conversation to do something to it... and then back to the list... using events to update the list of things (if necessary).

             

            • 3. Re: Conversations... Ending and Starting a new conversation in another controller.
              wangliyu

              CDI won't work that way, you have to do POST-REDIRECT-GET trick, first end() conversation in POST, and pass the parameters that you want to keep in the redirect, in GET begin() conversation. if you want some beans cross multiple conversations, then make it @SessionScoped.

              If you using JSF 2.1+, you have to do some trick (for example begin conversation in Before-RENDER-View-phase listener for GET request)

              1 of 1 people found this helpful
              • 4. Re: Conversations... Ending and Starting a new conversation in another controller.
                tony.herstell1

                Can you elaborate???

                >> POST-REDIRECT-GET trick

                I am very keen to see an example.

                 

                 

                >> if you want some beans cross multiple conversations, then make it @SessionScoped

                I have taken great PAIN in changing all my 15 SessionScoped "choose from a list of the XXX entites" beans over to RequestScope (and fixed all the LIEs in the process) for "efficiency" (even though I hammer the DB massively now)... I am not keen in adding in more Sessions Scoped beans if I can help it.

                I only need to pass an "Id" between the two conversation beans.

                • 5. Re: Conversations... Ending and Starting a new conversation in another controller.
                  wangliyu

                  POST(AJAX)-REDIRECT-GET:

                  in the normal JSF action, call Conversation.end(); and then return value that either configured in the faces-config.xml is redirect to next step or call return "targetPage?id={value}&PRG=true&faces-redirect=true";

                  create a BeforeRenderPagePhaseListener or page action, check if the PRG=true, Call "Coversation.begin()", also mapping the id to your bean's property.