5 Replies Latest reply on Oct 29, 2008 4:00 AM by Ingo Jobling

    Conversation state survives conversation end?

    Adam Warski Master

      Hello,


      I'm using the seam application framework to create and update an entity. I have the following declaration in components.xml:


      <framework:entity-home name="personHome" entity-class="Person" />



      I want to have one form to edit and create the pages, just as in the documentation. The link to create a new person looks as follows:


      <s:link view="/persons/edit_person.xhtml" value="New person" />



      (no id parameter). The id parameter is wired in pages.xml:


      <param name="personId" value="#{personHome.id}" converterId="javax.faces.Integer" />



      Now, if I create a person, and go back to the page, which displays the new person link, the link then contains a personId parameter, because s:link includes parameters in the link. But that is obviously not what I want - it makes the new person link a edit last created person link, if you don't refresh the page.


      I wanted to remedy the situation, by ending the conversation before the redirect:


      <navigation from-action="#{personHome.persist}">
         <end-conversation before-redirect="true" />
         <redirect view-id="/persons/list.xhtml"/>
      </navigation>



      as the personHome object is in the conversation scope, so the personId parameter would be forgotten, and s:link wouldn't add it. However, it still does ... any ideas why?


      Thanks,
      Adam

        • 1. Re: Conversation state survives conversation end?
          Dan Allen Master

          First of all, any time you are creating a link to create a new record, you should forcefully set the id parameter to blank:


          <s:link view="/PersonEdit.xhtml" value="New Person">
            <f:param name="personId"/>
          </s:link>



          As for your problem with the conversation propagating, you have to realize that page parameters are tricky because they activate components during page transitions, which can sometimes result in the creation of a new component that gets attached to the next conversation. This is likely what is happening in your case. The best bet is to nullify the id so that things don't happen down the road.

          • 2. Re: Conversation state survives conversation end?
            Adam Warski Master

            Ah, of course, thanks for the answer :)


            But anyway, why doesn't my method work? The component that the method parameter activates should be in the new conversation, so it shouldn't have the parameter set.


            As I understand what Seam does:



            • after the persist method is invoked, the conversation is ended

            • redirect to /persons/home.xhtml

            • the new view is rendered - this involves starting a new conversation

            • the s:link tag reads the parameter from the current conversation state



            Where am I wrong? :)


            Adam

            • 3. Re: Conversation state survives conversation end?
              Dan Allen Master

              Your bullets are correct. I can't explain what is going on without seeing more of the code. One possibility is that you are ending a nested conversation and the personHome is still defined in the parent conversation. Inspect the /debug.seam page and verify that after you return to the home page that there are no conversations active.




              As a general rule, I recommend two things when working with conversation. First, create a conversation switcher so that you can always see what conversations you have going. Second, keep the /debug.seam page open in another tab so that you can inspect what is in those conversations.
              • 4. Re: Conversation state survives conversation end?
                Adam Warski Master

                There are no nested conversations, and the /debug.seam page didn't tell me much ... here's example code if you'd like it:
                convtest
                (seam 2.0.2.sp1, the package is missing the lib dir as it's huge :) )


                --
                Adam

                • 5. Re: Conversation state survives conversation end?
                  Ingo Jobling Master

                  After screwing around for 3 hours, I finally crafted my magic command:



                  <s:button id="create" value="Create" view="/myView.xhtml" propagation="none" >
                       <f:param name="entityId"/>
                  </s:button> |
                  



                  This, on the other hand, does NOT end the conversation, and I can't understand why:


                  <h:commandButton id="create" value="Create" action="#{controller.create}" />
                  
                  public String create() {
                       return Constants.SUCCESS;
                  }
                  
                  <navigation from-action="#{controller.create}">
                       <rule>
                            <end-conversation/>
                            <redirect/>
                       </rule>
                  </navigation>
                  
                  22:41:01,717 DEBUG [org.jboss.seam.core.Manager] Restoring conversation with id: 1
                  


                  I wish that there was more about this in the Seam documentation!