0 Replies Latest reply on Jun 22, 2008 5:34 PM by mladen babic

    ExtendedDataModel firstRow is always 0

    mladen babic Newbie

      Hi,
      I have problem with showing data in rich datatable. Problem si that values in firstRow and numberOfRows in extendedDataModel are always 0. When I set any number in this variable, my dataProvider shows data as I've expected. This is snippet of my code :


      
      
      public class OrderDataModel extends SerializableDataModel {
      
       private PersistableDataProvider dataProvider;
      
       private Integer currentPk;
      private Integer rowsPerPage;
      
       private Map<Integer, PersistableObject> wrappedData = new HashMap<Integer, PersistableObject>();
      
       private List<Integer> wrappedKeys = null;
      
       private boolean detached = false;
      
       public OrderDataModel(PersistableDataProvider persistableDataProvider,Integer rows){
       dataProvider=persistableDataProvider;
       rowCount=rows;
       }
      
       private static final long serialVersionUID = -1956179896877538628L;
      
       @Override
       public Object getRowKey() {
      
       return currentPk;
      
       }
      
      
       @Override
       public void setRowKey(Object key) {
      
       this.currentPk = (Integer) key;
      
       }
      
      
      
       @Override
       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
      
      
       for (Integer key : wrappedKeys) {
       setRowKey(key);
       visitor.process(context, key, argument);
       }
       } else { // if not serialized, than we request data from data provider
      
       wrappedKeys = new ArrayList<Integer>();
       System.out.println("FIRST ROW "+firstRow);
       System.out.println("MAX ROWS"+numberOfRows);
       for (PersistableObject item : dataProvider.getItemsByRange(new Integer(firstRow), numberOfRows, null, true)) {
      
       wrappedKeys.add(item.getId());
      
       wrappedData.put(item.getId(), item);
      
       visitor.process(context, item.getId(), argument);
      
       }
      
       }
      
       }
      
      
      
       private Integer rowCount; // better to buffer row count locally
      
       @Override
       public int getRowCount() {
      
       if (rowCount == null) {
      
       rowCount = new Integer(dataProvider.getRowCount());
      
       return rowCount.intValue();
      
       } else {
      
       return rowCount.intValue();
      
       }
       }
      
      
       @Override
       public Object getRowData() {
      
       if (currentPk == null) {
      
       return null;
      
       } else {
      
       PersistableObject ret = wrappedData.get(currentPk);
      
       if (ret == null) {
      
       ret = dataProvider.getPersistableObjectById(currentPk);
      
       wrappedData.put(currentPk, ret);
      
       return ret;
      
       } else {
      
       return ret;
      
       }
      
       }
      
       }
      
       /**
      
       * Unused rudiment from old JSF staff.
      
       */
      
       @Override
       public int getRowIndex() {
      
       throw new UnsupportedOperationException();
      
       }
      
      
       @Override
       public Object getWrappedData() {
      
       throw new UnsupportedOperationException();
      
       }
      
      
       /**
      
       * Never called by framework.
      
       */
      
       @Override
       public boolean isRowAvailable() {
      
       if (currentPk == null) {
      
       return false;
      
       } else {
      
       return dataProvider.hasPersistableObject(currentPk);
      
       }
      
       }
      
       /**
      
       * Unused rudiment from old JSF staff.
      
       */
      
       @Override
       public void setRowIndex(int rowIndex) {
      
       throw new UnsupportedOperationException();
      
       }
      
      
       @Override
       public void setWrappedData(Object data) {
      
       throw new UnsupportedOperationException();
      
       }
      
      
      
       public PersistableDataProvider getdataProvider() {
       return dataProvider;
       }
      
       public void setDataProvider(PersistableDataProvider dataProvider) {
       this.dataProvider = dataProvider;
       }
      
      
       @Override
       public void update() {
       // TODO Auto-generated method stub
      
       }
      }
      
      
      
      


      And this is DataProvider

      
      @Name("orderDataProvider")
      public class OrderDataProvider extends AbstractPersistableDataProvider implements PersistableDataProvider{
      
       private OrderEntity order;
      
       public boolean hasPersistableObject(Integer id) {
       return getPersistableList().contains(getPersistableObjectById(id));
       }
      
       public List<PersistableObject> getItemsByRange(Integer firstResult,
       Integer maxResult, String orderBy, boolean asc) {
      
       return getPersistableList(firstResult,maxResult, orderBy,asc);
       }
      
      }
      
      
      and test page for datamodel

      <h:form id="myform">
      
       <rich:dataTable id="modeltable" var="ord" value="#{orderDataModel}" >
       <rich:column>
       <f:facet name="header">
       Order id
       </f:facet>
       <h:outputText value="#{ord.id}"></h:outputText>
       </rich:column>
      
       </rich:dataTable>
      
      
       </h:form>