Caution when using column filtering with a rich:extendedDataTable
langles Jan 8, 2010 7:37 PMI 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.