2 Replies Latest reply on Mar 10, 2007 3:51 PM by Stuart Robertson

    @DataModelSelection always set to first item in ListDataMode

    Stuart Robertson Novice

      First, this is Seam 1.2Patch1 on Jboss 4.0.5.

      In a nutshell, when I have a h:commandLink in a dataTable backed with a List, now matter which row's "clickable link" I select, the value in the variable annotated as @DataModelSelection is always the first element in the list.

      In my SFSB I have the following defined:

       @DataModelSelection(value="mappedColumns")
       protected FeedMappingColumn columnToDelete;
      
       @DataModel
       public List<FeedMappingColumn> getMappedColumns() {
       List<FeedMappingColumn> columns = new ArrayList<FeedMappingColumn>();
       columns.addAll(mappedColumns.values());
       return columns;
       }
      


      basically translating a map into a list for display purposes.

      The xhtml is as follows:

       <rich:dataTable id="mappedColumns" value="#{feedMapping.mappedColumns}"
       var="column">
       <h:column>
       <f:facet name="header">
       <h:outputText value="Column Number" />
       </f:facet>
       #{column.rawColumn.columnNumber}
       </h:column>
       <h:column>
       <h:commandLink value="del" action="#{feedMapping.removeMapping}"/>
       </h:column>
       </rich:dataTable>
      


      and #{feedMapping.removeMapping} looks like this:

       public void removeMapping() {
       int columnNumber = columnToDelete.getRawColumn().getColumnNumber();
       info("Deleting column #0. columnToDelete instance is #1", columnNumber, columnToDelete);
       FeedMappingColumn column = mappedColumns.remove(columnNumber);
      
       // make sure it's already mapped. If not this is a programming error
       assert column != null : "Column [" + columnNumber + "] isn't mapped. Shouldn't be presented with unmap option";
       assert column.getMappingCdmField() != null : "Column [" + columnNumber + "] is a mapped column but doesn't have a CdmField";
      
       // add the cdmField back to the list of available ones
       remainingCdmFields.put(column.getMappingCdmField().getCdmField(),column.getMappingCdmField());
       column.setMappingCdmField(null);
       unMappedColumns.put(columnNumber, column);
       }
      


      I've been over the logic many times this afternoon, and I don't think it's a logic error. And I just stepped through Seam's DataModelSelector class, and it's getSelection() method in the debugger. After I click on for instance the last row in the list, I see that the selected value is indeed whatever happens to be the first item in the list.

      Any ideas? I suspect it's a bug in the DataModel stuff, but want to get feedback before submitting something in Jira.