p:dataTable paginator is not updated after page change

UI Components for JSF
Post Reply
pdebski
Posts: 25
Joined: 17 Jan 2011, 15:15

17 Jan 2011, 15:32

Hi,
there is a problem with paginator update in dataTable component.

I have the following situation: table in database has 30 records, pageSize in datatable is set to 10 and the lazyLoading is set to true.
The first time dataTable is rendered there are 3 pages, each containing 10 rows.
Then I add a new row to database table (so now it has 31 rows) and then I go to page 2 but dataTable still has 30 rows on 3 pages, so I can't see the 31st element I've just added.
I expected the dataTable to update it's paginator, so now it would have 4 pages with 1 element on the last page.
Setting the rowCount property of LazyDataModel with new value every time I load new portion of data doesn't help.

I thing the problem is in DataTableRenderer in method encodeEnd - when the request is DataManipulationRequest then paginators should be re-rendered, because the total number of elements could change meanwhile and the number of pages would be out of date...

I think it should be fixed. Thanks!

Jimmy87_XFaces
Posts: 10
Joined: 21 Dec 2010, 08:02

19 Jan 2011, 22:01

Hi...in this post that I have posted, I did something like you say....in a dataTable, I used lazyLoad and works fine when show the data, as well as add a data and the dataTable is updated inmediatly..but my problem happneds when the last row in the last page is deleted..

http://primefaces.prime.com.tr/forum/vi ... 713#p28713

Please read the post and say me if it was that you are looking for...

And if you aren't the problem in delete row, please...say or post your code from lazyModel

pdebski
Posts: 25
Joined: 17 Jan 2011, 15:15

20 Jan 2011, 12:08

No, this is not my case.. I do not add a row through the application, but directly in database (which is similar situation to the one when the row is added from different application than mine) so I can't trigger an event "new row is added". But every time I change the page in dataTable, the new portion of data is read from database and I know the new size of the database table (inluding the new row) and I set this value in model:

Code: Select all

model.setRowCount((int) page.getNumberOfAllElements());
But unfortunately that instruction does not cause the update of paginator so I still can see only 3 pages instead of 4.
As I said in previous post the problem IMO is in DataTableRenderer, because it doesn't re-render paginator when the page is changed, it only re-renders rows of the table. And because of that even if the datatable got 100 new rows I would not see them until I make another POST request to this view..

Here is the code of LazyDataModel:

Code: Select all

private void initLazyDataModel() {
        model = new LazyDataModel<T>() {

            private static final long serialVersionUID = -4699044141564972423L;

            @Override
            public List<T> load(int first, int pageSize, String sortField, boolean sortOrder,
                Map<String, String> filters) {
                if (sortField != null) {
                    String order = sortOrder ? SortingOrder.ASC.toString() : SortingOrder.DESC.toString();
                    sortingOrder.clear();
                    sortingOrder.put(sortField, order);
                }
                Page<T> page = getPage(first / pageSize + 1, pageSize, sortingOrder);
                return setLazyDataModelSettings(page, this);
            }
        };

        model.setRowCount(1);
        model.setPageSize(DEFAULT_MAX_RESULTS);
    }

private List<T> setLazyDataModelSettings(Page<T> page, LazyDataModel<T> model) {
        if (page.getNumberOfAllElements() == 0) {
            model.setRowCount(0);
        } else {
            model.setRowCount((int) page.getNumberOfAllElements());
        }
        model.setPageSize(page.getMaxResultsPerPage());
        model.setWrappedData(page.getElementsList());
        pageRowCount = page.getElementsList().size();
        return page.getElementsList();
    }


cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

20 Jan 2011, 13:17

If you are sure that there is a bug in paginator regarding updates, please create an issue with your case so we can look in detail.


noodle
Posts: 5
Joined: 28 Feb 2011, 08:14

11 Mar 2011, 02:29

Not sure if it's same issue:

I have a lazyload datatable, has filter on few columns. After I input filter condition, the amount of data changed, In lazyloadmodel, already reset rowcount, but paginator didn't update number of pages. If you trigger filter again (give new value or just leave that field if it's event is blur), it will update. But that means it will always use last time rowcount, not current one.

noodle
Posts: 5
Joined: 28 Feb 2011, 08:14

11 Mar 2011, 02:32

By the way, if no value change in filter field, should it still trigger load data? In lazy mode, it's kind of unnecessary. isn't it?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 18 guests