question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Datatable: Lazy Loading and sort listener in wrong call order

See original GitHub issue

Describe the defect When I use a sort listener in a datatable with lazy loading, the load method is called before the sort listener method. It works fine with a page listener.

Environment:

  • PF Version: 10.0
  • JSF + version: MyFaces 2.3.6
  • Affected browsers: Chrome

To Reproduce Steps to reproduce the behavior: There is no showcase. See the code below.

Expected behavior In Version 8 the sort listener was called before the load method

Example XHTML

<p:dataTable value="#{controller.lazyDataModel}"
             lazy="true"
             sortMode="multiple"
             ...>

    <p:ajax event="sort" listener="#{controller.sortListener()}" process="@this" />
    <p:ajax event="page" listener="#{controller.pageListener()}" process="@this" />

...
</p:dataTable>

Example Bean

@Named
@ViewScoped
public class Controller implements Serializable {

    ...

    public void sortListener() {
        sortEvent = true;
    }

    public void pageListener() {
        pageEvent = true;
    }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mellowarecommented, May 18, 2021

Reproducer: pf-7164.zip

10:0.0:

LazyDataModel.load() called
TestView.sort() called
0reactions
mellowarecommented, May 18, 2021

Here is what happens when I dump the stack when the page first loads…

LazyDataModel.load() called
java.base/java.lang.Thread.getStackTrace(Thread.java:1607)
org.primefaces.test.LazyCustomerDataModel.load(LazyCustomerDataModel.java:68)
org.primefaces.component.datatable.DataTable.loadLazyData(DataTable.java:459)
org.primefaces.component.datatable.DataTableRenderer.preRender(DataTableRenderer.java:126)
org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:93)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:920)

But when the field is sorted you can see the “lazy” method is called in the SortFeature.

LazyDataModel.load() called
java.base/java.lang.Thread.getStackTrace(Thread.java:1607)
org.primefaces.test.LazyCustomerDataModel.load(LazyCustomerDataModel.java:68)
org.primefaces.component.datatable.DataTable.loadLazyData(DataTable.java:459)
org.primefaces.component.datatable.feature.SortFeature.decode(SortFeature.java:103)
org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:72)
javax.faces.component.UIComponentBase.decode(UIComponentBase.java:832)
org.primefaces.component.api.UIData.processDecodes(UIData.java:117)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom sort methods are not being called in lazy loading ...
1 Answer 1 ... The custom sort (or filter functions/methods) do not work when using lazy loading, nor are they intended to. In...
Read more >
DataTable Lazy loading with Sorting and filtering
I've a lazy loading datatable with sorting and filtering. ... which means that the load method is called by incorrect paging information.
Read more >
Useful PrimeFaces DataTable Events - Beyond Java
The listener function can either take no parameters, or it can take a SortEvent containing information which column is being sorted, and whether ......
Read more >
lazy « PrimeFaces « JSF Q&A - Java2s.com
i was developing lazy loading dataTable with primeface with pagination. SelectionMode is multiple. I was selected 3 check box in first page, now...
Read more >
DataTable - ICEfaces - ICEfaces.org Community Wiki
Expected type is a List or DataModel. Lazy loading requires an instance of the LazyDataModel object. Sub-row expansion requires a model of type ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found