10 Replies Latest reply on Oct 22, 2009 3:44 PM by bashan

    Ending of Seam Conversation

    visumagic
      Hi ALL,

      When ever I define @Begin in seam component , it's going to start a conversation for me. But when ever I'm navigating (not redirecting) to some other page ,i want to End the existing conversation.

      I can define @End method, but at the time of navigation I dont know which view user is going to choose.

      So I want to end the conversation when ever I move from existing page to some other page.
      @End(beforeRedirect=true) is not working as expected

      please help me..

      thanks
      raghu
        • 1. Re: Ending of Seam Conversation
          mail.micke

          If the conversation only is needed while you are on one page perhaps you can use the PAGE scope?


          That scope will keep the state of the backing beans while you remain on that page.


          What do you mean by navigating, the user clicking a link? If so perhaps you can use the <s:link> with the appropriate conversation ending attribute.


          - Micke

          • 2. Re: Ending of Seam Conversation
            visumagic

            Happy newyear Mike,
            thanks for your reply ..


            Little confusion here ..


            I'm using welcome.page.xml


            <action execute="#{profile.load}" if="#{user2 eq null}"/>



            Here profile,user2 is a page scoped component ..



            @Name("profile")
            @Scope(ScopeType.PAGE)
            public class ProfilePage {
              @Out (required=false,scope=ScopeType.PAGE)
                    User user2;
            
                    public void load(){
                         user2=entityManager.find(User.class, id);
                 }
            ....
            } 




            load method is getting executed every time, ajax/normal form submission.


            But I was expecting the user2 will be remained in the scope for
            consecutive ajax/normal form submissions


            plz help me ..
            thanks
            raghu


            • 3. Re: Ending of Seam Conversation
              mail.micke

              Hi Raghu


              I'm doing a similar thing myself, but instead of checking the presence of an outjected object I check a boolean variable in the backing bean.


              Something like this:


              <action execute="#{profile.load}" if="#{profile.doInit}"/>
              



              And then I have a doInit boolean variable which I set to false the first time load is called.


              Hope this helps,
              Micke

              • 4. Re: Ending of Seam Conversation
                visumagic

                hi Micke,


                I will follow your suggestion . this solution will be common for all
                page scoped components.


                thanks
                raghu


                I Love Seam

                • 5. Re: Ending of Seam Conversation
                  mail.micke

                  Glad I could help :)


                  FYI:


                  Usually I don't need to worry about that kind of stuff because I use the @Create annotation which only executes the method once.


                  The only time I need to use that page.xml hack is when I need to inject request parameters via page.xml, turns out that those parameters aren't injected/set at the time the @Create method is executed ( they are injected by then if using @RequestParameter.

                  • 6. Re: Ending of Seam Conversation
                    bashan

                    Hi all,
                    I have the same problem: I have a single page with Ajax actions. When using CONVERSATION scope all is working great, but when navigating to the previous page and selecting a different item from a list, shows the page with the previous item. I assume this happens since conversation was not ended. I change the scope of the bean to: PAGE, but all my Ajax operations are failing on: org.hibernate.PersistentObjectException: detached entity passed to persist.


                    Any solution to that?

                    • 7. Re: Ending of Seam Conversation
                      asookazian

                      guy bashan wrote on Oct 21, 2009 23:27:


                      Hi all,
                      I have the same problem: I have a single page with Ajax actions. When using CONVERSATION scope all is working great, but when navigating to the previous page and selecting a different item from a list, shows the page with the previous item. I assume this happens since conversation was not ended. I change the scope of the bean to: PAGE, but all my Ajax operations are failing on: org.hibernate.PersistentObjectException: detached entity passed to persist.

                      Any solution to that?


                      Why is the entity detached?  If you use SMPC with Hibernate manual flush, the entities should remain attached for the duration of a LRC.  Generally speaking, it is not advised to use PAGE scope unless you only are dealing with one page (not a wizard), you're better off using LRC. 

                      • 8. Re: Ending of Seam Conversation
                        bashan

                        Hi Arbi,


                        I assume the entity is detached since I changed the bean from CONVERSATION scope to PAGE scope. It seems like working with PAGE scope bean, an Hibernate session is generated per request and not for the whole conversation. Am I right?
                        I usually don't have wizards in my web-apps, but single page being edited or showing information. Is PAGE scope bean or CONVERSATION scope bean is the right choice?


                        Thanks,
                        Guy.

                        • 9. Re: Ending of Seam Conversation

                          guy bashan wrote on Oct 21, 2009 23:27:


                          Hi all,
                          I have the same problem: I have a single page with Ajax actions. When using CONVERSATION scope all is working great, but when navigating to the previous page and selecting a different item from a list, shows the page with the previous item. I assume this happens since conversation was not ended. I change the scope of the bean to: PAGE, but all my Ajax operations are failing on: org.hibernate.PersistentObjectException: detached entity passed to persist.

                          Any solution to that?


                          The way I work when editing an entity is always in a conversation. If it's just one page, it doesn't matter.


                          I always manage the conversations through the front end instead of the back end. I think that I'm more flexible in the way I can create, propagate and destroy conversations. In that case I use the conversationPropagation = none if I have to put a link to another page. In that case, I do not finish the previous conversation and the new page gets a new temporary conversation so no state is shared between pages.


                          Hope it helps.

                          • 10. Re: Ending of Seam Conversation
                            bashan

                            Hi Santiago,


                            I work pretty much the same: All of my links set to no propagation and most of the pages are simply a CONVERSATION of a single page. This makes the server side work more neat and easy, since the objects are loaded once and then manipulated and changed as needed using Ajax requests or simple post.
                            I have 2 questions that I am not sure about:
                            1) Is this the right way of working (does the PAGE scope is better for these scenarios)?
                            2) As far as I understand, for entities to stay attached, an Hibernate session is managed by Seam on the server side for the whole conversation. Won't it make a problem if the server will get a high amount of requests (it terms of opening many connections to the database, assuming there is a database connection for each conversation...)


                            Thanks,
                            Guy.