ajax4jsf

Where is the SequenceRange from the walk-method from ExtendedDataModel defined?


The ExtendedDataModel from ajax4jsf uses a method called walk, looking like this:

public void walk(FacesContext ctx, DataVisitor dv, Range range, Object argument){}

This method is called several times in my application. Some topics on internet seem to say that it the latter is defined by the rows="x" in the xhtml. However, for me range is always defined as 0 (firstRow) - -1 (getRows).

So I was wondering where this range is defined, so I can figure out why the wrong parameters are passed to it. Debugging and googling hasn't helped me so far.


Solution

  • Range represents visible part of data displayed in table. If you have paginator, then paginator display which page (= from which row to which row) data is presented.

    Problem can be in incorrect value of rows attribute of data table (for example rows attribute is missing).

    Other place can be in incorrect implementation of data model. Object of data model class can be used as storage for data displayed in rich:dataTable.

    Real example:

    public class VSDataModel<RecordType> extends ExtendedDataModel<RecordType> implements Arrangeable {
    
        private final FetchList<RecordType> list;
    
        @Override
        public void walk(FacesContext ctx, DataVisitor visitor, Range range, Object obj) {
            try {
                int firstRow = ((SequenceRange) range).getFirstRow();
                int numberOfRows = ((SequenceRange) range).getRows();
                if(list == null) {
                    throw new RuntimeException("Underlying list is null!");
                }
                if(list.getList() == null || firstRow != list.getFirstRow()) {
                    list.fetch(firstRow, numberOfRows);
                }
                for (RecordType elem : list.getList()) {
                    visitor.process(ctx, list.getPK(elem), obj);
                }
            } catch(Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
    

    It is used in Java private VSDataModel<Record> dependentList; and html <rich:dataTable value="#{bean.dependentList}" rows="#{referenceData.recordsPerPage}">