DisplayTag
  1. DisplayTag
  2. DISPL-209

getListIndex() does not return the real list index

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.0
    • Fix Version/s: 1.1
    • Component/s: Decorators, Paging/Sorting
    • Labels:
      None
    • Application server:
      weblogic

      Description

      getListIndex() seems to return the same value as getViewIndex() after sorting a list/table.
      According to my understanding of the api, getListIndex() should always return the index of the object in the original unsorted list/table.

        Activity

        Hide
        Tom Tibbetts added a comment -
        I found that the Row object contains the original index of the unsorted list in the form of rowNumber. When it is passed to the table decorator via table decorator's init function, rowNumber gets reset to the sorted index. I've done a search on clients to Row.getRowNumber and found no users, so I went ahead and removed the line that resets the rowNumber to the sorted index and that seems to work.
        Show
        Tom Tibbetts added a comment - I found that the Row object contains the original index of the unsorted list in the form of rowNumber. When it is passed to the table decorator via table decorator's init function, rowNumber gets reset to the sorted index. I've done a search on clients to Row.getRowNumber and found no users, so I went ahead and removed the line that resets the rowNumber to the sorted index and that seems to work.
        Hide
        Tom Tibbetts added a comment -
        in RowIterator.java replace the code for the next() method with the following code:

            public Row next()
            {

                int currentRowNumber = this.rowNumber++;

                if (log.isDebugEnabled())
                {
                    log.debug("[" + this.id + "] rowIterator.next() row number=" + currentRowNumber);
                }

                Object object = this.iterator.next();

                Row row = (Row) object;
                int listIndex = row.getRowNumber() - 1;

                row.setRowNumber(currentRowNumber);

                if (this.decorator != null)
                {
                    this.decorator.initRow(row.getObject(), currentRowNumber, listIndex);
                }

                return row;

            }
        Show
        Tom Tibbetts added a comment - in RowIterator.java replace the code for the next() method with the following code:     public Row next()     {         int currentRowNumber = this.rowNumber++;         if (log.isDebugEnabled())         {             log.debug("[" + this.id + "] rowIterator.next() row number=" + currentRowNumber);         }         Object object = this.iterator.next();         Row row = (Row) object;         int listIndex = row.getRowNumber() - 1;         row.setRowNumber(currentRowNumber);         if (this.decorator != null)         {             this.decorator.initRow(row.getObject(), currentRowNumber, listIndex);         }         return row;     }
        Hide
        fabrizio giustina added a comment -
        I reviewed the patch supplied, but the value returned by getListIndex() will not be the correct one.
        Actually, there is no way to get the correct index in the original, unsorter list: doing this will require iterating throug all the list for each object to get its original position (and still it will not work for duplicate objects).
        getListIndex() returns the list in the FULL list, but after sorting (so it's the same as the view index + page offset). I added a note about this to the TableDecorator javadocs.
        Closing since it can't be fixed.
        Show
        fabrizio giustina added a comment - I reviewed the patch supplied, but the value returned by getListIndex() will not be the correct one. Actually, there is no way to get the correct index in the original, unsorter list: doing this will require iterating throug all the list for each object to get its original position (and still it will not work for duplicate objects). getListIndex() returns the list in the FULL list, but after sorting (so it's the same as the view index + page offset). I added a note about this to the TableDecorator javadocs. Closing since it can't be fixed.

          People

          • Reporter:
            Patrick Ehrensperger
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: