1 Reply Latest reply on Aug 16, 2010 3:43 PM by Rafael Ribeiro

    rich:scrollableDataTable and DataModel.getRowCount returning -1 leads to unexpected behavior

    Rafael Ribeiro Novice

      Hi all,

       

      We are trying to implement a scrollable data model that does not rely upon a prior counting of the result set. javax.faces.model.DataModel.getRowCount javadoc suggest that this method should return -1 "If the number of rows is unknown," but when we implemented our DataModel that implements SerializableDataModel we noticed that the Range parameter passed to the walk method on our ExtendedDataModel had a range from 0 to -1. After some investigation we noticed that org.richfaces.component.UIScrollableDataTable.createComponentState() was the responsible for such strange behavior and I'll paste it below:

      {code}

      protected DataComponentState createComponentState() {
         
              return new DataComponentState(){
             
                  public Range getRange() {
                     
                      int curentRow = getFirst();

       

                      int rows;
                      if(reqRowsCount == -1 ){
                          rows = getRows();
                      } else {
                          rows = reqRowsCount;
                      }
                                     
                      int rowsCount = getExtendedDataModel().getRowCount();
                     
                      if(rows > 0){
                     
                          rows += curentRow;
                         
                          if(rows >=0){
                              rows = Math.min(rows, rowsCount);
                          }
                         
                      } else if(rowsCount >=0 ){
                          rows = rowsCount;
                         
                      } else {
                          rows = -1;
                      }
                     
                      return new ScrollableTableDataRange(curentRow,rows, getSortOrder());
                  }
              };
          }

      {code}

      We noticed that the following part:

      {code}

                   if(rows > 0){
                      
                           rows += curentRow;
                          
                           if(rows >=0){
                               rows = Math.min(rows, rowsCount);
                           }

      {code}

      was rather strange since after adding something non negative to rows it wouldn't never return anything smaller or equal to zero and therefore it would always evaluathe the code inside this if. Also as we were returning -1 from DataModel.getRowCount it got -1 which lead to the -1 limit on range parameter (as mentioned above). Shouldn't it return rows in case it was -1?

      Anyways in our debug session we forced rows to see the outcome and unfortunately it resulted in a single page being fetched (with the number of rows we specified on rows variable)... instead of a "load on demand" behavior as we expected...

       

      Is there any way to accomplish what we are trying to do? Is this method supposed to be as it is now?

       

      regards,

      Rafael Ribeiro