1

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;
    }

}
Jean-Charles
  • 1,690
  • 17
  • 28

2 Answers2

1

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.

Ken Chan
  • 84,777
  • 26
  • 143
  • 172
  • "the sortOrder and the datatable pagination do not have relationship to affect each others." I agree, this is why I posted ;) Otherwise, I'll update and see. Thanks for your tips – Jean-Charles Sep 12 '11 at 13:36
  • Changing to 3.3.3.Final, I have problem with unresolved ExtendedTableDataModel. I've found out the ExtendedTableDataModel class in [latest_3_3_X](http://docs.jboss.org/richfaces/latest_3_3_X/en/apidoc_impl/org/richfaces/model/ExtendedTableDataModel.html), but not in [3.3.3.Final](http://docs.jboss.org/richfaces/3.3.X/3.3.3.Final/en/apidoc/). Is this class removed in 3.3.3 ? – Jean-Charles Sep 12 '11 at 14:35
  • Finding ExtendedTableDataModel in [documentation](http://docs.jboss.org/richfaces/3.3.X/3.3.3.Final/en/apidoc_impl/), but not in the jar... Is this class removed in 3.3.3 jar ? – Jean-Charles Sep 12 '11 at 14:44
  • @Jean-Charles I can find ExtendedTableDataModel in the `richfaces-impl-3.3.3.Final.jar` – Ken Chan Sep 12 '11 at 15:59
  • See my comment on Andrey answer to know that the upgrade doesn't correct the bug. Any other idea or recommendation? – Jean-Charles Sep 13 '11 at 07:53
1

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);
Andrey
  • 6,526
  • 3
  • 39
  • 58
  • I upgraded to 3.3.3.Final, but the problem is still here. I still can correct it adding the sortOrder on the column. For information, I now using : ` org.richfaces.ui richfaces-ui 3.3.3.Final org.richfaces.framework richfaces-impl 3.3.3.Final ` – Jean-Charles Sep 13 '11 at 07:50
  • @Jean-Charles Have you tried using another table model implementation (refer to UPDATE section)? – Andrey Sep 16 '11 at 08:14
  • I'm doing it... But I've priority works which stop me in the development. For the time being, using ListDataModel, I can't retrieve the selected line, `getRowData()` returns null. how to declare `rich:extendedDataTable` and have the row in `getRowData()`? – Jean-Charles Sep 16 '11 at 08:18
  • I give you the bounty before it'll expire but the solution isn't implemented yet. I'm not eable to get the selected value without use a dataprovider. Can you help me how to use ListDataModel and extendedDataTable? More, can you tell me why I don't have to use ExtendedTableDataModel? – Jean-Charles Sep 16 '11 at 13:37
  • @Jean-Charles ExtendedTableDataModel has some strange implementation of walk method. And also there is a tricky implementation of the richDataTable component. It wraps dataModel with ExtendedTableDataModifiableModel in case you have sort columns, otherwise it passes your dataTable as is. – Andrey Sep 16 '11 at 13:47
  • I would also try doing in such way: new ExtendedTableDataModifiableModel(yourDataProvider); and also such way: new SequenceDataModel(yourDataModel); – Andrey Sep 16 '11 at 13:53
  • @Jean-Charles Hm, I have reproduced the issue on my environment. No of my suggestions helps :(. Will dig it further. – Andrey Sep 16 '11 at 15:38
  • Even in 3.3.3: With ExtendedTableDataModel the datascroller doesn't work. With ExtendedTableDataModifiableModel ou ListDataModel, I can't get the object selected. Why dataProvider interact with datascroller? If you can make ListDataModel workable, I'll be the best solution. Thanks for your help – Jean-Charles Sep 16 '11 at 15:46
  • @Jean-Charles dataProvider does not interact with datascroller. Actual lifecycle is as following: datascroller invokes setFirst() method on dataTable component, then dataTable invokes walk() method on dataModel. Problem is that ExtendedTableDataModel caches data, and returns that data regardless of Range parameter passed. – Andrey Sep 18 '11 at 13:51
  • Also selection works good for both ExtendedTableDataModifiableModel and ListDataModel. If you need ExtendedTableDataModel for some reason do so: new ExtendedTableDataModifiableModel(yourExtendedTableDataModel, null); – Andrey Sep 18 '11 at 13:56