2 Replies Latest reply on Apr 3, 2008 3:19 PM by Guillaume Jeudy

    Parallel conversations question

    Bogdan Minciu Newbie

      Hello,


      Suppose I have this CONVERSATION scoped component:


      @Stateful
      @Name("blogEntryCreate")
      @Scope(ScopeType.CONVERSATION)
      @Restrict("#{identity.loggedIn}")
      public class BlogEntryCreateBean implements LocalBlogEntryCreate {
      ...
          @Out(required = false)
          private BlogEntry newBlogEntry;
          
          @Begin(join = true)
          public void addBlogEntry() {
              newBlogEntry = new BlogEntry();
          }
      
          @End
          public void persist() {
              ...
              blogEntryDAO.persist(newBlogEntry);
              FacesMessages.instance().add("BlogEntry created.");
          }
      ...
      }
      



      The create blogEntry procedure is started by this s:link:


      <s:link action="#{blogEntryCreate.addBlogEntry()}" view="/xcms/blog/blogEntryCreate.xhtml" value="BlogEntry Create"/>
      



      Well, my question is pretty simple. As you can see, the @Begin(join=true) doesn't really start a new conversation for each browser-tab in which the user wants to start a new adding procedure. Instead, it joins the new tab that adds the blogEntry to the old conversation. But, if there is some data added to the newBlogEntry variable from the other already started conversations (from previous browser-tabs) they will also be available on the newBlogEntry variable from the newly 'started' conversation. In other words, there isn't really started a new conversation, only joined an existing one.


      I have only added join=true to get rid of the exception:


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



      My question is: how can I start a really NEW conversation in each tab even if a long running conversation is already opened? Or what other design/approach do you suggest?


      Thank you in advance for any hint,


      Bogdan.

        • 1. Re: Parallel conversations question
          Jacob Orshalick Apprentice

          Change your s:link to the following:


          <s:link action="#{blogEntryCreate.addBlogEntry()}" 
            view="/xcms/blog/blogEntryCreate.xhtml" 
            value="BlogEntry Create" propagation="none" />



          propagation of none ensures that the cid is not sent in the request and the conversation is not propagated.  This way you will have a new conversation every time a blog entry is created.


          Hope that helps.

          • 2. Re: Parallel conversations question
            Guillaume Jeudy Master

            You can try nesting a conversation. Try:


            @Begin(nested=true)



            This way your newBlogEntry will be outjected to the inner conversation scope allowing you to have several newBlogEntry in parallel conversations. Each time @End method is called it will end the current conversation (depends from which context you call it).


            I encourage you to experiment and view the seam debug page to track your conversations.


            Regards,
            -Guillaume