Question

I had a problem on a Jsf page. The datascroller didn't change pagination of the dataTable clicking on a number of page (still stay on the first page of the pagination).

  • Richfaces : 3.3.2.SR1
  • Jsf : 1.2
  • JBoss 5.0.1

This code doesn't change the pagination :

<rich:extendedDataTable id="tableDataTable" value="#{beanController.listTableDataModel}" 
    var="tableItem" selectionMode="single"
    rows="3" width="150px" height="100px" selection="#{beanController.tableSelection}">

    <rich:column sortBy="#{tableItem.code}" width="150px" label="#{msg.table}">
        <h:outputText value="#{tableItem.code}" />
    </rich:column>
    <rich:column sortBy="#{tableItem.code}" width="150px" label="#{msg.table}">
        <h:outputText value="#{tableItem.code}" />
    </rich:column>
</rich:extendedDataTable>
<rich:datascroller id="tableDataScroller" align="center" for="tableDataTable" renderIfSinglePage="false" />

I solved it defining the sortOrder attribute. This works fine (only one difference : sortOrder="ASCENDING" on a column):

<rich:extendedDataTable id="tableDataTable" value="#{beanController.listTableDataModel}" 
    var="tableItem" selectionMode="single"
    rows="3" width="150px" height="100px" selection="#{beanController.tableSelection}">

    <rich:column sortBy="#{tableItem.code}" width="150px" label="#{msg.table}" sortOrder="ASCENDING">
        <h:outputText value="#{tableItem.code}" />
    </rich:column>
    <rich:column sortBy="#{tableItem.code}" width="150px" label="#{msg.table}">
        <h:outputText value="#{tableItem.code}" />
    </rich:column>
</rich:extendedDataTable>
<rich:datascroller id="tableDataScroller" align="center" for="tableDataTable" renderIfSinglePage="false" />

The question is Why do we have to define the sortOrder to correct the datatable pagination using datascroller ? Any idea ?

Edit : DataProvider Code

public class BeanDataProvider implements DataProvider<Bean> {


    private static final long serialVersionUID = -3539248649798786324L;

    public BeanDataProvider() {
    }

    public BeanDataProvider(ArrayList<Bean> beans) {
        this.beans = beans;
    }

    private List<Bean> beans;


    public Bean getItemByKey(Object paramObject) {
        Bean resultat = null;
        for (Bean bean : this.getBeans()) {
            if (bean.getIdentifiant().equals(paramObject)) {
                resultat = bean;
                break;
            }
        }
        return resultat;
    }


    public List<Bean> getItemsByRange(int paramInt1, int paramInt2) {
        return this.getBeans().subList(paramInt1, paramInt2);
    }


    public Object getKey(Bean paramT) {
        return paramT.getIdentifiant();
    }


    public int getRowCount() {
        return this.getBeans().size();
    }


    public List<Bean> getBeans() {
        if (beans == null) {
            beans = new ArrayList<Bean>();
        }
        return beans;
    }


    public void setbeans(List<Bean> beans) {
        this.beans = beans;
    }

}
Was it helpful?

Solution

It is a bug in RichFaces:

TableSorting - Built-in - pages cannot be switched by DataScroller

When clicked on the numbered page (e.g. 2) in the initial state, page wasn't switched.

The table was re-rendered well after clicking on the sorted-column's header.

Upgrading to 3.3.3.Final should help.

Regarding ExtendedTableDataModel:

It is available in 3.3.3.Final (org.richfaces.model.ExtendedTableDataModel in richfaces-impl-3.3.3.Final.jar). And it is also available in the documentation: http://docs.jboss.org/richfaces/3.3.X/3.3.3.Final/en/apidoc_impl/ (../apidoc_impl/ is used for richfaces-impl, ../apidoc/ is used for richfaces-ui).

It is not available in RF4. In RF4 explore these classes:

org.richfaces.model.ArrangeableState
org.ajax4jsf.model.ExtendedDataModel
org.richfaces.model.ArrangeableModel

UPDATE:

Use ExtendedTableDataModifiableModel instead of ExtendedTableDataModel:

new ExtendedTableDataModifiableModel(dataProvider);

Or even better (when list is used as a data source as in your case):

new ListDataModel(list);

OTHER TIPS

Tested your code using richfaces 3.3.3 and it works fine .The pagination can changed in both cases. So I think the sortOrder and the datatable pagination do not have relationship to affect each others.

And I found the release note of RichFaces - Version 3.3.3.BETA1 has some bug fixes about the rich:datascroller . Perhaps you can upgrade to richfaces 3.3.3 in your DEV environment to see if the problems are still there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top