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.

DataGrid and DataTable: rows- and first-attributes ignored after use of paginator

See original GitHub issue

1) Environment

  • PrimeFaces version: 7.0/7.1-SNAPSHOT
  • Does it work on the newest released PrimeFaces version? Version? No, neither with 7.0, nor with 7.1-SNAPSHOT.
  • Does it work on the newest sources in GitHub? (Build by source -> https://github.com/primefaces/primefaces/wiki/Building-From-Source). No.
  • Application server + version: Tested with Wildfly 11 and Jetty 9.4.15 from the primefaces-test project.
  • Affected browsers: probably all (tested with Firefox 60.7.0esr, Opera 58 and Chromium 75). Note: Opera and Chromium seem to have other problems with 7.1-SNAPSHOT, which is probably unrelated)

2) Expected behavior

The rows-attribute from the <p:dataGrid> component should always use the actual value.

3) Actual behavior

After the use of the pager, the rows-attribute seems to be ignored and the last value before the pager was used is always used, no matter what the actual value of the rows EL is.

4) Steps to reproduce

  • clone https://github.com/matinh/primefaces-test.git using the branch dataGrid with git clone 'https://github.com/matinh/primefaces-test.git' -b dataGrid
  • change directory cd primefaces-test
  • run mvn jetty:run-exploded
  • goto http://localhost:8080/primefaces-test/
  • use the spinner to change number of rows in the dataGrid
  • use pager to switch to another page
  • try to use spinner again to change number of rows, which is no longer working.

Further comments

  • There are no JavaScript Errors in the browsers console.
  • The setter of the columns-attribute is called with the correct value.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
Rawi01commented, Jun 24, 2019

I checked some primefaces sources and it seems like the problem is in L297 https://github.com/primefaces/primefaces/blob/e2062dc5671b10e9f3913b454d4c31b86a62c226/src/main/java/org/primefaces/component/api/UIData.java#L290-L307

A possible fix might be to check for an exisitng value expression as in L305 and only set that value to the new one e.g.

ValueExpression rowsVe = data.getValueExpression("rows"); 

if (rowsVe != null && !rowsVe.isReadOnly(elContext)) { 
    rowsVe.setValue(context.getELContext(), Integer.valueOf(rowsParam)); 
} else {
    data.setRows(Integer.valueOf(rowsParam));
}
1reaction
matinhcommented, Jun 26, 2019

Ok, I did some further research to see what actually happens. Here we go: The DataGridRenderer when rendering the grid, only uses UIData.getRows() and never queries the ValueExpression directly.

UIData.getRows() is like this:

    return (Integer) getStateHelper().eval(PropertyKeys.rows, 0);

and eval() is defined like this:

    public Object eval(Serializable key, Object defaultValue) {
        Object retVal = get(key);
        if (retVal == null) {
            ValueExpression ve = component.getValueExpression(key.toString());
            if (ve != null) {
                retVal = ve.getValue(component.getFacesContext().getELContext());
            }
        }
        return ((retVal != null) ? retVal : defaultValue);
    }

So as long as setRows() was not called, getRows() effectively uses component.getValueExpression('rows') which is what we want.

When the pager is used, updatePagination() is called which, in the unmodified version, sets the new rows-value to whtaever was submitted by the pager: https://github.com/primefaces/primefaces/blob/e2062dc5671b10e9f3913b454d4c31b86a62c226/src/main/java/org/primefaces/component/api/UIData.java#L283-L297

From now on, calls to UIData.getRows() return the last value submitted by the pager and never use the ValueExpression like before.

The changes from PR https://github.com/primefaces/primefaces/pull/4937 now avoid using the setter when a ValueExpression was used for the corresponding attributes but instead write to the ValueExpression. Only when no (writeable) VE was in use the submitted value is written directly into the component state.

Conclusion: IMHO the suggested fix should be ok. I’m not 100% sure if this is the suggested way, how PrimeFaces components should handle this situation, but currently I do not see any problems with this approach and I did quite some testing with DataGrid, and DataTable, included filtering, sorting, mutiViewState, paging, etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML5 data-* is being ignored — DataTables forums
Hey there, I'm trying to to sort one of our tables based off of a prescribed value according to the contextual value of...
Read more >
jQuery datatable ignores rows with colspan - Stack Overflow
I recommend to use this solution direct from datatable. DataTables hidden row details example. works great.
Read more >
Pagination: Core Feature of our Datagrid - AG Grid
One such feature is Pagination. Use Pagination when you don't want the user to have to scroll. Pagination allows viewing rows one page...
Read more >
Post processing of search results patent application class
Embodiments of the present invention organize and view data using abstract records. Specifically, users compose a query according to the logical relationships ...
Read more >
Page 13 – Angular, PWA, C#, ASP.NET, Node ... - Bhavin Patel
Angular apps are modular and so in general we assemble our application from many modules. A typical module is a cohesive block of...
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