0 Replies Latest reply on Sep 18, 2008 10:29 AM by mario.balaban

    problem using ExtendedDataModel for dataTable

      I need to display a table with data coming from a db query with many records (~1000) so it seemed obvious to me that ExtendedDataModel should be used. As starting point I used example classes that could be found at :
      http://viewvc.jboss.org/cgi-bin/viewvc.cgi/richfaces/branches/3.1.x/samples/richfaces-demo/src/main/java/org/richfaces/demo/extendeddatamodel/

      I changed the AuctionDataProvider method in this way:

      public List getItemsByrange(Integer startPk, int numberOfRows, String sortField, boolean ascending) {
      
       return dataAccessObject.getSubSetOfItems(startPk, startPk+numberOfRows);
       }
      


      this method is invoked by the walk method in AuctionDataModel

      public void walk(FacesContext context, DataVisitor visitor, Range range, Object argument) throws IOException {
       int firstRow = ((SequenceRange)range).getFirstRow();
       int numberOfRows = ((SequenceRange)range).getRows();
       if (detached) { // Is this serialized model
      // Here we just ignore current Rage and use whatever data was saved in serialized model.
      // Such approach uses much more getByPk() operations, instead of just one request by range.
      // Concrete case may be different from that, so you can just load data from data provider by range.
      // We are using wrappedKeys list only to preserve actual order of items.
       for (Iterator iterator = wrappedKeys.iterator(); iterator.hasNext();) {
       Integer key = (Integer) iterator.next();
       setRowKey(key);
       visitor.process(context, key, argument);
       }
       } else { // if not serialized, than we request data from data provider
       wrappedKeys = new ArrayList();
       for (Iterator iterator = dataProvider.getItemsByrange(new Integer(firstRow), numberOfRows, null, true).iterator();
       iterator.hasNext();) {
      
       AuctionItem item = (AuctionItem) iterator.next();
      
       wrappedKeys.add(item.getPk());
       wrappedData.put(item.getPk(), item);
       visitor.process(context, item.getPk(), argument);
       }
       }
       }
      


      I imagine that the assignments made at the begging of the walk method
      int firstRow = ((SequenceRange)range).getFirstRow();
      int numberOfRows = ((SequenceRange)range).getRows();

      should change during navigation from one page of data to another, but debugging I see that firstRow always is set to 0 (zero) and numberOfRows to -1, no mater what is the value of rows attribute in the dataTable tag:

      <rich:dataTable cellpadding="0" cellspacing="0" width="100%" border="0" var="recordElenco" rows="10" value="#{auctionDataModel}".....


      so I cannot get the paged data from the db.

      I experienced the problem with 3.2.2 and 3.2.1 releases. My application server is jboss.4.2.2GA.