10 Replies Latest reply on Apr 21, 2009 9:36 PM by brandonsimpson

    Ending conversation but objects still remain in conversation scope

      I have a problem ending a conversation. I have a dataTable, there is a link for each column. If a user clicks on a link the current object will be put into conversation scope, a long running conversation will be started and the user will be forwarded (no redirect) to a new page. Additional objects and collections will be put in the conversation on the detail pages.


      Here's the problem: When the user goes back to the overview page (which contains the dataTable) and clicks the above mentioned link for another row, the current conversation must be ended (if one exists) and a new one needs to be started. I am using the following code snipped in the action method for that link but the code does not work as expected. The old objects and collections still remain in the same conversation. Here's the code:


      if (Conversation.instance().isLongRunning()) {
        Conversation.instance().end();
        Conversation.instance().begin(false, false);
      } else {
        Conversation.instance().begin();
      }



      I created a test case where I called the end() method in a separate request, the conversation will be destroyed and all objects were removed. Why does that not work for one request? What is wrong with my understanding / code? Have I forgot something?


      Thanks in advance!

        • 1. Re: Ending conversation but objects still remain in conversation scope

          Anyone can help?

          • 2. Re: Ending conversation but objects still remain in conversation scope
            obfuscator

            There is always a conversation present, and it can be temporary or long-running.


            If the conversation is long-running, which can be set by using @Begin, the context gets propagated to the next request of the same user (session). If not (temporary conversation), the context will be destroyed when the request ends. @End merely tells Seam to demote the conversation to temporary.


            A conversation context will not be destroyed during a request, because the context has the same life-span as a request (in practice it is bound to the current thread as a ThreadLocal).


            There is lots and lots of documentation on this. Read the docs.

            • 3. Re: Ending conversation but objects still remain in conversation scope
              obfuscator

              Hmm, I managed to sneak errors into my text already. You can end the conversation before a redirect if you use @End(beforeRedirect=true)

              • 4. Re: Ending conversation but objects still remain in conversation scope
                digdas.seam.digdas.nl

                Looks a bit like my problem.


                I use the EntityHome on the new page - as created by JBoss Tools  - New Entity.


                When a user clicks on the menu for the list, then clicks on one of the rows to edit, then clicks on the menu to see the list again, and clicks on another row to edit, the first row is visible.


                To avoid this problem, so the new row to edit is edited, I changed the RequestParameter in the home object:


                    @RequestParameter 
                     public void setMdaIcnMonthsId(Long mdaIcnMonthsId) {
                         if (mdaIcnMonthsId != null)
                              if (this.getConversation().isLongRunning())
                                   if (this.instance != null)
                                        if (this.instance.getKey() != null)
                                             if (this.instance.getKey().compareTo(mdaIcnMonthsId) != 0 )
                                             {
                                                  this.instance = getEntityManager().find(MdaIcnMonths.class, mdaIcnMonthsId);
                                             }
                         
                          this.mdaIcnMonthsId = mdaIcnMonthsId;
                     }



                But this seems to me a bit wrong. Is it, or what should I do. Have not found an answer on forum or book...

                • 5. Re: Ending conversation but objects still remain in conversation scope
                  obfuscator

                  read this

                  • 6. Re: Ending conversation but objects still remain in conversation scope
                    digdas.seam.digdas.nl

                    Thanks, I am reading this.


                    But I can not find the answer...


                    The example I use was created by Seam - Create new entity. A list object and a home object together with the xhtml-pages is created.
                    The standard behaviour is as I stated:



                    When a user clicks on the menu for the list, then clicks on one of the rows to edit, then clicks on the menu to see the list again, and clicks on another row to edit, the first row is visible

                    In the example use is made of an action method to select the correct object.
                    I am looking for something to use this option and work with the correct object.


                    The code I am using here does the trick, but I think it is nasty to do it like this.

                    • 7. Re: Ending conversation but objects still remain in conversation scope

                      I used a workaround to avoid these problem in my code. I thought that when I stop a conversation with @End or programatically with Conversation.instance().end(); that all objects stored in that conversation will be destroyed. Unfortunately, that is only true if I do no start a new conversation within the same request (no redirect). Or isn't it?


                      Currently I am using

                      @Begin(join=true)

                      so there is no need to end the current conversation and start a new one but all existing objects won't be destroyed. Is there a solution to destroy all objects in a conversation?

                      • 8. Re: Ending conversation but objects still remain in conversation scope
                        coldgin

                        Yep, you are right. I had the same issue with my objects not being destroyed after the conversation ended. I specified <end-conversation before-redirect="true"/>, and then the objects were destroyed.

                        Thanks.

                        • 9. Re: Ending conversation but objects still remain in conversation scope
                          brandonsimpson

                          From my understanding, ending the conversation just makes it a temp conversation again. It doesn't clean up any objects in the conversation. Normally these would only be cleaned up when the temp conversation then ends.


                          If you need to end a long conversation and start another fresh in the same method, you'd probably need to do some manual cleanup.

                          • 10. Re: Ending conversation but objects still remain in conversation scope
                            brandonsimpson

                            Sorry...forgot to say you could probably get the conversation context and do a clear() on it and not worry about ending/starting conversation.