4 Replies Latest reply on Mar 25, 2010 6:12 PM by Ryan Nideffer

    Conversation propagation across form post

    Ryan Nideffer Newbie

      I'm having a difficult time maintaining a conversation across a form post. I have the following:


      <h:commandButton value="Submit" action="#{bean.submit}"/>
      



      the normal page flow works, my from-action navigation rule is processed, but a necessary URL parameter is not passed to one of my component methods.


      I want to be able to do this:


      <h:commandButton value="Submit" action="#{bean.submit}">
          <f:param name="#{manager.conversationIdParameter}" value="#{conversation.id}"/>
      </h:commandButton>
      



      But as soon as I add that parameter phases 4 and 5 do not happen. My submit method is never called, and my navigation rules are not processed. The form posts to the exact same page, with none of the injected or url parameters I need.


      Why does this not work?

        • 1. Re: Conversation propagation across form post
          Tim Evers Master

          Bonquisha Shoniqua wrote on Mar 24, 2010 18:30:


          I'm having a difficult time maintaining a conversation across a form post. I have the following:

          <h:commandButton value="Submit" action="#{bean.submit}"/>
          



          the normal page flow works, my from-action navigation rule is processed, but a necessary URL parameter is not passed to one of my component methods.

          I want to be able to do this:

          <h:commandButton value="Submit" action="#{bean.submit}">
              <f:param name="#{manager.conversationIdParameter}" value="#{conversation.id}"/>
          </h:commandButton>
          



          But as soon as I add that parameter phases 4 and 5 do not happen. My submit method is never called, and my navigation rules are not processed. The form posts to the exact same page, with none of the injected or url parameters I need.

          Why does this not work?


          You should never(well, almost never) need to add the conversationIdParam to your submit button manually like that.


          Why do you think that that is the param that you need to be passing anyway?


          What error are you getting?


          Is there anything in your logs?


          Are you sure you are actually in a LONG running conversation? Do you have an @Begin(join=true) somewhere in your Seam Bean, or on that submit method?


          Please post your Seam Bean code so we can see what you are trying to achieve.

          • 2. Re: Conversation propagation across form post
            Ryan Nideffer Newbie

            Tim Evers wrote on Mar 25, 2010 00:19:


            You should never(well, almost never) need to add the conversationIdParam to your submit button manually like that.

            Why do you think that that is the param that you need to be passing anyway?

            What error are you getting?

            Is there anything in your logs?

            Are you sure you are actually in a LONG running conversation? Do you have an @Begin(join=true) somewhere in your Seam Bean, or on that submit method?

            Please post your Seam Bean code so we can see what you are trying to achieve.


            The problem I'm trying to solve is that of having an arbitrarily long list of

            <h:selectOneRadio>

            groups. So rather than have the backing bean method declared explicitly, I'm using a map, keyed by a String that is used to create the current radio group:


                                <ui:repeat value="#{bean.contests}" var="contestName">
                                    <p>Choose candidate for contest #{contestName}</p>
                                    <h:selectOneRadio value="#{bean.selections[contestName]}" layout="pageDirection">
                                        <f:selectItems value="#{bean.candidates}"/>
                                    </h:selectOneRadio>
                                </ui:repeat>
                                <h:commandButton value="Submit" action="#{bean.submit}"/>
            
            



            Its a voting application with the concept of ballots, contests per ballot, and candidates per contest. The ballotName is a URL parameter set when the user chooses a ballot to vote on. I have @Begin(join=true) on the method that displays the ballot names. The conversation id is propagated for me up to this point. The issue I'm having is that to populate the map, the list of strings returned from bean.getContests() needs to be the same each time for the map to be populated. Since this is a conversation scoped component, I simply maintain that list as an instance variable. However, after clicking submit, a new conversation is created, and a new bean component, obviously without the list of contest names. So I am looking for a way to keep the same conversation id on submit of the form. I try passing it manually, both with f:param and s:conversationId, and it causes the issue in my original post - no errors, phases being skipped, control never making it to my application.

            • 3. Re: Conversation propagation across form post
              Tim Evers Master

              Ok, so the real issue here is that your conversation is ending when it shouldn't?


              Just to be sure we are on the same page.


              (Most of these comments are true in the general sense but some can have very subtle things that cause them to be false under very rare circumstances)


              Once a conversation is closed you CANNOT access variables that were in that conversation.


              A LONG running conversation (started with @Begin) will remain a long running conversation UNTIL you end it (@End or other methods of ending a conversation).




              So, based on those two comments what are you doing?


              Is your submit method annotated with @End and then you are trying to access the variable again?


              If that is not the case are you starting a new conversation manually?



              I need to see the code. What you have described isn't making much sense from a Seam perspective. A long running conversation does not end on a post.



              Or maybe you are looking for a way to pass a param from one conversation to another. If this is the case then you can't. (OK, I lie, but from the strict view point of passing from one conversation to another it is impossible.) If this is what you are after then you need to use a Session scoped bean to do the passing of the param. There is no possible way to have 2 conversations active at the same time without causing much pain. Alternatively I am led to believe that you can pass params between conversations using pages.xml but I have not personally tried this so I cannot help on that one.


              If you are serious about passing params to different conversations then maybe take a look at what I wrote in This thread about Programmatic navigation.

              • 4. Re: Conversation propagation across form post
                Ryan Nideffer Newbie

                Hi Tim-


                I had a single method marked as @Begin, and no methods marked as @End. No matter what I did, I was having a new conversation id created when I clicked 'Submit'. I have since changed the code to be more granular, with respect to Session, Conversation and Event scope. I hope to have solved the problem that way.


                I do appreciate your assistance, and I would eventually like to get to the bottom of it. I know its due to a lack of my understanding of JSF/Seam, and I think part of it was that I designed the backing beans incorrectly.


                Thanks,
                Ryan