Rerender on scrollableDataTable with a changed model does no
opr Jun 26, 2008 3:07 AMHello,
I am dealing with the following problem.
I use a scrollable data table with an underlying Data Model in my backing bean. The model class implements the method loadData(..) which fetches the requested elements from a list of data.
public List loadData(int startRow, int endRow, SortOrder sortOrder) { System.out.println("Loading from " + startRow + " to " + endRow); return vendors.subList(startRow, endRow); }
The amount of data to represent in the table is very large so I decided to specify the row-Attribute with a value of 10. This makes the table to load the data incrementally. Without this attribute performance is bad.
<rich:scrollableDataTable sortMode="single" rows="10" id="vendorTable" selectedClass="tableSelection" value="#{vendorBean.vendorModel}" var="vendor" height="120px" binding="#{vendorBean.htmlScrollableDataTable}" rowKeyVar="rkv" selection="#{vendorBean.selectedRows}"> ...
So far, so good. Because of the large amount of data I added an input field and an a4j-commandButton to implement a filter on the data. When pressing the button an ajax request takes the value from the field and the backing bean recalculates the model. When the request is complete the table is rerendered and loadData crashes because of invalid indexes (startRow > endRow). This happens only when the filter button is pressed after scrolling the table down and further data was loaded from the model, so startRow is greater than zero.
I read that this is a bug, because startRow should be set to zero. Someone implemented a phase listener to call setFirst(0) and setRowIndex(0) on the table whenever this component is rendered. This workaround does not work for me, because it seems that the phase listener is not called on an ajax rerender.
When putting the following code at the beginning of the filter method, resetting the starting row to zero works but the table shows a strange behaviour. For a second you can see the filtered data without table headers. After that when rendering the headers the table is empty.
UIComponent comp = FacesContext.getCurrentInstance().getViewRoot().findComponent("vendor:vendorTable"); if (comp instanceof UIData) { UIData data = (UIData) comp; data.setFirst(0); data.setRowIndex(0); }
Has anyone an idea to make this work? This is actually a complete show stopper for our project.
Thanks a lot.