UPDATE II: OK, I managed to narrow it down a little.
I have a page with a datatable with sorting and filtering functionalities, both taking place in the DB. In other words, I do not use the embedded functionality of the rich:datatable I use, but rather let the DB do the work.
I work with request-scoped beans. The only session-scoped beans contain the sorting and filtering of my interface.
Filtering for each column is bound to the certain session bean fields. As such, it is actually updated during the Update Model Values phase.
Sorting required some logic from my part, so I invoke a certain method to set the correct values to the session bean. This is performed during the Invoke Application phase.
So, any changes are in place during the Render Response phase, where the page actually renders.
The problem is that the JSF datatable and datascroller in my page call the backingBean.getDataModel()
that fetch the data from the DB and the dataModel.getRowCount()
(which I have implemented to invoke a method that runs a separate query) also during the Apply Request Values phase. These two queries take also place during the Render Response Phase, which is the only phase where the changes are all in place, and the query will run normally.
This means that to show a page after I perform filtering or sorting, the double number of queries take place.
I want to perform sorting and filtering only performing the required queries and no more.
Any suggestions?