1 Reply Latest reply on May 13, 2008 3:23 PM by Ryan McDonough

    DataModelSelection and rich:datatable with Ajax4jsf

    Ryan McDonough Newbie

      I have a screen with 3 rich:datatables on a screen in order to represent the hieracrhy of an entity. The Seam-component is a JavaBean and we currently have it session-scoped as we're having some challenges with conversation-scoped JavaBean.


      @Name("presentationAction")
      @Scope(ScopeType.SESSION)
      public class PresentationAction {
      
          @Logger
          private Log log;
          
          /**
           * The PresentationDAO is a Spring Bean using a Seam-Managed 
           * Hibernate Session
           */
          @In("#{presentationDAO}")
          public PresentationDAO presentationDAO;
      
          @DataModel("valueList")
          public List<PresentationValue> valueList;
      
          /**
           * The DataTable that the valueList is bound to
           */
          private UIDataTable valueTable;
      
          /**
           * The selected fund
           */
          @DataModelSelection("presentationValue")
          public PresentationValue presentationValue;
          
          /**
           * The list of fund components for the selected fund.
           */
          @DataModel("componentList")
          public List<Component<?>> componentList;
      
          /**
           * The selected fund component.
           */
          @DataModelSelection("componentList")
          private Component<?> selectedComponent;
          
          /**
           * The data table the components are bound to
           */
          private UIDataTable componentTable;
      
          /**
           * 
           */
          @DataModel("attributeList")
          private List<ComponentAttribute> attributeList;
      
          /**
           * 
           */
          private UIDataTable attributeTable;
          ...


         
      The UI tables are bound to rich:datatable and are each updated using an a4j:support support element on the table. The attributeList table is editable and we allow the user to make changes here. In that respect, everything works and the data is properly persisted.


      Now the problem is that we're always editing the 1st PresentationValue that was selected. If you initially selected PresentationValue 3 and makde changes to it and proceeded to make changes to PresentationValue 5, you'd still be editing PresentationValue 3.


      It doesn't appear that @DataModelSelection works with a4j and rich:dataTable, but I am not entirely convinced yet. My assuption is that the bean is improperly scoped and/or needs some additional configuration.


      Another approach we tried was to get the current selection by doing:


       public void componentRowListener(ActionEvent event) {
              int selectedIndex = geComponentTable().getRowIndex();
              selectedComponent = (Component<?>) componentList.get(selectedIndex);
              attributeList = new ArrayList<ComponentAttribute>();
              ...
              


      This kinda worked in that we get the proper values, but the attributeList values are now disassociated from the owning PresentationValue and save no longer works. Now we could create method to reassociate those values, but it seems counter to what Seam provides. Any insight to what we are doing wrong would be apreciated!


      Ryan-