9 Replies Latest reply on Aug 21, 2010 7:55 AM by nigiyan

    Get the Component (conversation scoped) by conversation ID

    nigiyan

      Hi, All I wonder if it is possible to get conversation scoped Component (actually the entity) by conversation ID. I implemented Seam Workspace and it is possible to switch between conversations by choosing corresponding item. Now I need to have a feature similar to Windows/Linux windows switching (when press Alt+Tab) but applied for conversations. And I need to get the entities from corresponding conversations. How to do it and is it possible?

        • 1. Re: Get the Component (conversation scoped) by conversation ID
          asookazian

          Hi Aram, vonc es?


          Referring to section 7.2.1 of SiA book, there is a 1:1 ratio between LRC and workspace in a particular session.


          If you are using Seam-managed persistence context (SMPC) via @In rather than @PersistenceContext, then the SMPC is conversation scoped.


          IIRC when you switch workspaces, a new LRC becomes foreground (active) and the others are background (inactive and potentially may be destroyed when/if they timeout).


          So any CRUD operation you exec via JPA EntityManager will affect the active LRC's SMPC.  In other words, there should be no need to worry about filtering the PC for a particular conversation id, etc.


          If you read SiA book, there is some code there which shows how to display the active workspace/conversation, etc.


          HTH.

          • 2. Re: Get the Component (conversation scoped) by conversation ID
            nigiyan

            Barev, Arbi! (Greeting in Armenian),

            Imagine, you have opened same Entity for editing in different conversations. How do you get their states?
            (with em.find(MyEntity.class, myEntityInstaceId) - only instance _of current_ conversation and possible to get only _from current_ conversation and not for instance from session component)

            • 3. Re: Get the Component (conversation scoped) by conversation ID
              asookazian

              For any entity, you access their state via EntityManager API for JPA or Session API for Hibernate.


              Each EntityManager manages a particular persistence context.


              Each SMPC is conversation-scoped.  So every time you switch a workspace/conversation, the EntityManager will access a managed instance of entity Foo.


              The current LRC is the active one.


              So it's simple, you just do it and when you do it's getting it from the current SMPC.  You don't have to specify any conversationId AFAIK.


              If you wanted to access an entity from a background conversation, then that's a different story (you'd have to make it active or perhaps there's a Seam API to handle that case).

              • 4. Re: Get the Component (conversation scoped) by conversation ID
                nigiyan

                Arbi Sookazian wrote on Apr 13, 2010 17:46:

                If you wanted to access an entity from a background conversation, then that's a different story (you'd have to make it active or perhaps there's a Seam API to handle that case).


                If "background conversation" you mentioned is just another conversation joined to long running one, then this is exactly what I'm asking...

                • 5. Re: Get the Component (conversation scoped) by conversation ID
                  asookazian

                  Let's say you have two Seam components.


                  @Scope(ScopeType.CONVERSATION)
                  @Name("foo")
                  public class Foo {
                      
                      @Begin(join=true)
                      public void start() {}
                  
                  }



                  @Scope(ScopeType.CONVERSATION)
                  @Name("bar")
                  public class Bar {
                      
                      @Begin(join=true)
                      public void start() {}
                  
                  }



                  If foo.start() is invoked first and no LRC exists, then the current temporary conversation is promoted to a LRC.  If subsequently bar.start() is invoked, then the bar component joins the active LRC.


                  In this scenario, there is no background conversation and the active conversation will timeout with the session.


                  http://solutionsfit.com/blog/2007/12/13/explaining-the-conversation-timeout-setting-through-example/


                  I don't think it's possible for a background conversation to join another conversation, whether active or background.  It's whether or not another Seam component may join the current LRC or not...

                  • 6. Re: Get the Component (conversation scoped) by conversation ID
                    nigiyan

                    Please read about "concurrent conversations" and "workspace switcher"
                    from here
                    or the live preview

                    • 7. Re: Get the Component (conversation scoped) by conversation ID
                      nigiyan

                      From the book:



                      ...Click on the description link to load the selected conversation in the current window. Seam maintains a list of concurrent conversations in the current user session in a component named conversationList. You can iterate through the list to see the descriptions of the conversations, their start times, and last access times. The conversationList component also provides a means of loading any conversation in the current workspace (browser window or tab).


                      Now, I don't need to do
                      conversationEntry.select()
                      I want to get the Entity(ies) from the active conversation(s).


                      • 8. Re: Get the Component (conversation scoped) by conversation ID
                        nigiyan

                        This task is no longer actual for me, however, investigating ConversationEntry class recently, I found probable useful class which may act as start point for further research:


                        org.jboss.seam.contexts.ServerConversationContext

                        • 9. Re: Get the Component (conversation scoped) by conversation ID
                          nigiyan

                          I've debugged this class and it is really what is needed.