2 Replies Latest reply on Mar 11, 2013 11:03 AM by mbickel

    Seam-2.3 conversation scope propagation on a4j:ajax event?

    mbickel

      Still migrating from Seam-2.2 to Seam-2.3 (using RF-4.3.0 here). I have a view that is backed by one conversation-scoped and several session scoped beans. My problem is that my xingManager.authorize() action method is not called because seam doesn't seem to be able to grab the correct conversation bean and save the changes made to the h:selectOneMenu below:

       

      <h:form>
        <h:selectOneMenu value="#{manager.hint}">
          <f:selectItems value="#{listFactory.allHints}" />
          <a4j:ajax render="choicePanel" />
        </h:selectOneMenu>
        <a4j:outputPanel id="choicePanel">
          <a4j:outputPanel rendered="#{manager.hint == 'LINKEDIN'}">
            ...
          </a4j:outputPanel>
          <a4j:outputPanel id="xingPanel" rendered="#{manager.hint == 'XING'}">
            <a4j:outputPanel rendered="#{!xingManager.authorized}">
              <a4j:commandButton action="#{xingManager.authorize}" execute="@form" render="xingPanel" />
            </a4j:outputPanel>
          </a4j:outputPanel>
        </a4j:outputPanel>
      </h:form>
      

       

      When I switch around in the h:selectOneMenu, ajax events are generated and processed just fine. The "choicePanel" gets updated as it should, but on clicking the a4j:commandButton the associated action does not get called. After some hours of debugging I found that manager.hint isn't set to 'XING' in the backing bean when restoring the view (even though it *was* set by the ajax call before).

       

      The corresponding beans are something like this:

       

      @Name("manager")
      @Scope(ScopeType.CONVERSATION)
      public class Manager {
        public HintEnum { LINKEDIN, XING };
        private HintEnum hint;
        // getter and setter
      }
      

       

       

      @Name("xingManager")
      @Scope(ScopeType.SESSION)
      public class XingManager {
        public void authorize() { /* send authorization request to 3rd party API */ }
        public boolean getAuthorized() { /* query logged in user component */ }
      }
      

       

      The listFactory.allHints property just returns all values() of the enum above.

       

      I found that lifting the Manager bean to ScopeType.SESSION "fixed" the issue and the action was called just fine. I deduced that seam failed to notice and restore the conversation, but even manually adding the conversation id to the ajax request didn't help. Since I rely on conversation scope to make tabbed browsing "just work" I'm pretty much stuck with conversation scope. Have I missed something that would make the example work with conversation scope or is going session scope the only option in this case?

        • 1. Re: Seam-2.3 conversation scope propagation on a4j:ajax event?
          petros

          Hi Matti,

          have you tried to add hidden input with conversation id? I had a similar case and adding <input type="hidden" name="cid" value='#{conversation.id}' /> was helpfull.

          • 2. Re: Seam-2.3 conversation scope propagation on a4j:ajax event?
            mbickel

            Thanks for the response! Yes, that's what I meant with "manually adding conversation id". Still the same result.

             

            Further debugging by breakpointing org.jboss.seam.core.Manager.restoreConversation() shows that seam is indeed able to extract the conversationId but it always points to a non-existant ConversationEntry.

            Which finally points me to the issue: I had removed the seam-2 specific .page.xml for the view that contained an <action> element that elevated the conversation to a long-running one (annotated with @Begin). Restoring the file made seam store & find the conversation again.

             

            Now, follow-up question: can I somehow migrate that action to the template as shown in http://mkblog.exadel.com/2010/07/learning-jsf2-page-params-and-page-actions/ via the <f:event type="preRenderView" /> tag? Because right now that will not elevate the conversation and I'm back to square one.

             

            Edited with more debugging info