4 Replies Latest reply on Mar 23, 2006 5:37 PM by gavin.king

    Component Binding to conversation does not work

    scraatz

      Hi,

      we are trying to bind a faces UI component to a conversation.scope Java bean with SEAM 1.0B2 and myFaces 1.1.1/facelets.
      Whenever the form is postet SEAM complains that "no conversation is active" and throws an exception.

      <h:inputText value="#{conversation.input}" binding="#{conversation.inputComponent}" />
      


      Question: Am I doing something wrong? Is there a workaround?

      Thanks
      Stefan

      P.S.:
      After looking at the SEAM and myFaces source I believe that the problem is, that SEAM restores the current conversation in the AFTER_PHASE listener of RESTORE_VIEW,

       public void afterPhase(PhaseEvent event)
       {
       log.trace( "after phase: " + event.getPhaseId() );
      
       if ( event.getPhaseId() == RESTORE_VIEW )
       {
       restoreAnyConversationContext(event);
       }
       else if ( event.getPhaseId() == RENDER_RESPONSE )
      ....
      


      and myFaces sets the bindings before calling the AFTER_PHASE listener

      ....
       recursivelyHandleComponentReferencesAndSetValid(facesContext, viewRoot);
      
       informPhaseListenersAfter(facesContext, PhaseId.RESTORE_VIEW);
      ....
      
      


      Just moving the SEAM-code to the other Phase does not work, because the
      restoreAnyConversationContext(event); method accesses the component tree.

      When is the conversationID stored in the request-params and when attached to the UIViewRoot?



        • 1. Re: Component Binding to conversation does not work

          I've found a way around this.

          In my CONVERSATION scoped component I inject an EVENT scoped component, which handles the binding.

          So my conversation component looks something like:

          @Stateful
          @Name("cart")
          @Interceptors(SeamInterceptor.class)
          public class ShoppingCartBean implements ShoppingCart, Serializable {
          ...
           @In(value="cartTable", create=true)
           private transient TableBinding table;
          ...
          }
          


          And my event component looks something like:
          @Name("cartTable")
          @Scope(ScopeType.EVENT)
          public class ShoppingCartTableBinding extends TableBinding {
          }
          


          Just for completeness, my TableBinding class is used to bind to a ADF Faces Table component:
          public abstract class TableBinding {
          
           private UIXTable table;
          
           public UIXTable getBinding() {
           return table;
           }
          
           public void setBinding(UIXTable table) {
           this.table = table;
           }
          
           public List getSelectedRows() {
           List selectedRows = new ArrayList();
          
           Object oldKey = table.getRowKey();
           Set<String> selectedKeys = table.getSelectionState().getKeySet();
          
           for (String rowKey : selectedKeys) {
           table.setRowKey(rowKey);
           selectedRows.add(table.getRowData());
           }
          
           table.setRowKey(oldKey);
          
           return selectedRows;
           }
          
           public void clearSelection() {
           table.getSelectionState().clear();
           }
          }
          

          And my JSF page looks something like:
          ...
           <af:table binding="#{cartTable.binding}" ...>
          ...
          


          • 2. Re: Component Binding to conversation does not work
            gavin.king

            The Conversation context is not available during the restore view phase. Hence the problem ;)

            • 3. Re: Component Binding to conversation does not work
              scraatz

              Gavin,

              is this by design or will it be fixed in later versions?

              • 4. Re: Component Binding to conversation does not work
                gavin.king

                it is unavoidable