3 Replies Latest reply on Jan 14, 2010 1:58 PM by langles

    Caution when using column filtering with a rich:extendedDataTable

      I discovered an issue with using column filtering with a rich:extendedDataTable that I backed with a custom DataModel class.  Because of lines 362-266 of the RichFaces class:   /ui/extendedDataTable/src/main/java/org/richfaces/component/UIExtendedDataTable.java  {code}                        else {                                 ModifiableModel modifiableModel = new ModifiableModel(dataModel, getVar());                                 dataModel = modifiableModel;                                 modifiable = modifiableModel;                         }{code}  using column filtering can cause a dataModel for an extendedDataTable to be wrapped by a instance of org.rich.model.ModifiableModel.  The implementation of ModifiableModel, rather ignorantly, uses the row index as input to the rowKey variable in the walk() function passed to the DataVisitor class (lines 142- 158)   {code}        @Override         public void walk(FacesContext context, DataVisitor visitor, Range range,                         Object argument) throws IOException {                 final SequenceRange seqRange = (SequenceRange) range;                 int rows = seqRange.getRows();                 int rowCount = getRowCount();                 int currentRow = seqRange.getFirstRow();                 if(rows > 0){                         rows += currentRow;                         rows = Math.min(rows, rowCount);                 } else {                         rows = rowCount;                 }                 for (; currentRow < rows; currentRow++) {                         visitor.process(context, currentRow, argument);                 }         }{code}  The ExtendedTableDataModifiableModel class has a much better implementation:  {code}        @Override         public void walk(FacesContext context, DataVisitor visitor, Range range,                         Object argument) throws IOException {                 final SequenceRange seqRange = (SequenceRange) range;                 int rows = seqRange.getRows();                 int rowCount = getRowCount();                 int currentRow = seqRange.getFirstRow();                 if(rows > 0){                         rows += currentRow;                         rows = Math.min(rows, rowCount);                 } else {                         rows = rowCount;                 }                 for (; currentRow < rows; currentRow++) {                         visitor.process(context, rowKeys.get(currentRow), argument);                 }         }{code}  So If you are going to use filtering with your rich:extendedDataTable, then use a dataModel that evaluates as an instance of   ExtendedTableDataModel or your  own implementation that directly implements the Modifable interface.
        • 1. Re: Caution when using column filtering with a rich:extendedDataTable
          kukeltje
          can you please repost with correct formatting?
          • 2. Re: Caution when using column filtering with a rich:extendedDataTable
            deleted...
            • 3. Re: Caution when using column filtering with a rich:extendedDataTable
              I discovered an issue with using column filtering with a rich:extendedDataTable that I backed with a custom DataModel class.

              Because of lines 362-266 of the RichFaces class:

              /ui/extendedDataTable/src/main/java/org/richfaces/component/UIExtendedDataTable.java

                                      else {
                                              ModifiableModel modifiableModel = new ModifiableModel(dataModel, getVar());
                                              dataModel = modifiableModel;
                                              modifiable = modifiableModel;
                                      }
              
              
              using column filtering can cause a dataModel for an extendedDataTable to be wrapped by a instance of org.rich.model.ModifiableModel.

              The implementation of ModifiableModel, rather ignorantly, uses the row index as input to the rowKey variable in the walk() function passed to the DataVisitor class (lines 142- 158)

                      @Override
                      public void walk(FacesContext context, DataVisitor visitor, Range range,
                                      Object argument) throws IOException {
                              final SequenceRange seqRange = (SequenceRange) range;
                              int rows = seqRange.getRows();
                              int rowCount = getRowCount();
                              int currentRow = seqRange.getFirstRow();
                              if(rows > 0){
                                      rows += currentRow;
                                      rows = Math.min(rows, rowCount);
                              } else {
                                      rows = rowCount;
                              }
                              for (; currentRow < rows; currentRow++) {
                                      visitor.process(context, currentRow, argument);
                              }
                      }
              
              The ExtendedTableDataModifiableModel class has a much better implementation:
                      @Override
                      public void walk(FacesContext context, DataVisitor visitor, Range range,
                                      Object argument) throws IOException {
                              final SequenceRange seqRange = (SequenceRange) range;
                              int rows = seqRange.getRows();
                              int rowCount = getRowCount();
                              int currentRow = seqRange.getFirstRow();
                              if(rows > 0){
                                      rows += currentRow;
                                      rows = Math.min(rows, rowCount);
                              } else {
                                      rows = rowCount;
                              }
                              for (; currentRow < rows; currentRow++) {
                                      visitor.process(context, rowKeys.get(currentRow), argument);
                              }
                      }
              
              So If you are going to use filtering with your rich:extendedDataTable, then use a dataModel that evaluates as an instance of:

                ExtendedTableDataModel  or your  own implementation that directly implements the Modifable interface.