0 Replies Latest reply on May 31, 2012 10:14 AM by Nikolai Alexeev

    Lazy loading extendedDataTable

    Nikolai Alexeev Newbie

      Is it possible to leave loaded data in data table when ajax loading is on? I mean that by default this loading works in the manner that it always loads only fixed number of rows cleaning all other. Is it possible to leave already loaded values by standard means or i have to make it in our custom data model?

      -------

      Well, i tried to modify my model to achieve my goal but i've faced a problem with visitor.process(). When list is first loaded org.richfaces.renderkit.AbstractRowsRenderer is used as visitor and its process() method is called. This doesn't cause any problems and entries are shown on the page. But when i scroll down and application tries to load new entries other visitors are used: org.richfaces.component.UIDataAdaptor's ComponentVisitor and two anonymous visitors from org.richfaces.renderkit.ExtendedDataTableRenderer. UIDataAdaptor's ComponentVisitor doesn't cause any problems while anonymous do. First of them adds existing row ids to a LinkedList (see ids.add(...) line):

       

      table.walk(context, new DataVisitor() {
          public DataVisitResult process(FacesContext context, Object rowKey, Object argument) {
              UIDataTableBase dataTable = state.getRow();
              dataTable.setRowKey(context, rowKey);
              ids.add(dataTable.getContainerClientId(context) + ":" + state.getPart().getName().getId());
                  return DataVisitResult.CONTINUE;
          }
      }, removeRange, null);
      

      And the second somehow tries to update them by removing their ids from created list. Of course when it tries to update new entries which aren't available in the table yet it fails with IndexOutOfBoundsException (see writer.updateAttributes(ids.remove(0), attributes); line):

       

      table.walk(context, new DataVisitor() {
          public DataVisitResult process(FacesContext context, Object rowKey, Object argument) {
              UIDataTableBase dataTable = state.getRow();
              dataTable.setRowKey(context, rowKey);
              HashMap<String, String> attributes = new HashMap<String, String>(1);
              String id = dataTable.getContainerClientId(context) + ":" + state.getPart().getName().getId();
              attributes.put("id", id);
              try {
                  writer.updateAttributes(ids.remove(0), attributes);
                  writer.startUpdate(id);
                  encodeRow(writer, context, state);
                  writer.endUpdate();
              } catch (IOException e) {
                  throw new FacesException(e);
              }
              RowHolderBase holder = (RowHolderBase) argument;
              holder.nextRow();
              return DataVisitResult.CONTINUE;
          }
      }, addRange, state);
      

      Is it possible to call first visitor after new entries are added to the list or maybe use other DataVisitor at all?