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