www.teamdev.com

This Question is Answered

1 "helpful" answer available (2 pts)
5 Replies Last post: Aug 1, 2008 6:47 PM by westd  
Click to view westd's profile   9 posts since
Apr 30, 2008

Jul 25, 2008 7:07 PM

How to execute JSF action method while using custom data providing sorting/filtering


Hi,

I am using Quipukit custom sorting/filtering in a datatable. I want to update the result set from my database in the JSF application phase, rather than the render response phase.

As such, I want to read the quipukit request parameters for paging/sorting/filtering in a JSF action method, at which point I will execute my database query. Later in the render response phase, I will return the stored results. I am using JBOSS Seam and this is the recommended way of doing things in all their examples - it avoids the double query problem mentioned in your datatable documentation.

I've seen the q_refreshTable method can take an action method name, but how do I specify an action method to be called when a user clicks on a table heading to sort, changes a filter value, etc.?

Looking forward to your response

David

Click to view Dmitry Pikhulya's profile TeamDev Ltd. 147 posts since
Jan 5, 2007
1. Jul 28, 2008 8:16 PM in response to: westd
Re: How to execute JSF action method while using custom data providing sorting/filtering
Hello David,

There is no feature for invoking an action on changing custom data providing parameters (such as sorting and filtering). Theoretically this shouldn't be needed, so I would like to clarify your use case. If I understand your actual problem correctly, you see the old data when performing sorting, filtering and pagination because @Facotry or @DataModel is invoked two times during a request, and JBoss Seam uses the cached data during the second fetch. Is this correct? Please tell which scope does your @Factory method have? Theoretically, the PAGE scope should solve the caching problem that I mentioned because it starts during the invoke application phase prior to rendering a page, and lasts until the invoke application phase of a next request that originated from that page. So this way you should be able to just load the fresh data from within a @Factory method and avoid the need for any additional events from a DataTable. Please tell if there are problems with this approach.

Nevertheless, there's one more approach if using the PAGE scope doesn't solve the problem for some reason. Please note that you can bind all of the data loading parameters (page index, sorting and filtering parameters) to a backing bean. So it is possible to write a phase listener that will just take these parameters before (or after) the "invoke application" phase and load the fresh data accordingly.

Regards,
Dmitry
Click to view Dmitry Pikhulya's profile TeamDev Ltd. 147 posts since
Jan 5, 2007
4. Aug 1, 2008 6:23 PM in response to: westd
Re: How to execute JSF action method while using custom data providing sorting/filtering
Hello David,

You need to explicitly use bindings for all of the data providing parameters to make my second suggestion work. The "pageStart" and "pageSize" parameters are indeed available only when DataTable makes data requests itself, and can't be accessed at any time. Instead of using these parameters you can bind the DataTable's "pageIndex" attribute and calculate the pageStart parameter given the page size specified in your table. The following snippet illustrates the idea:

<q:dataTable ... pageIndex="#{testBean.pageIndex}" pageSize="#{testBean.pageSize}" ...>
...


... and here's a backing bean code that calculates the pageStart and pageSize parameters:

...
private int myPageSize = 15;
private int myPageIndex = 0;
 
public int getPageSize() {
  return myPageSize;
}
public void setPageIndex(int pageIndex) { 
  myPageIndex = pageIndex;
}
public int getPageIndex() {
  return myPageIndex;
}
...
private void reloadData() {
...
  int pageStart = myPageIndex * myPageSize;
  int pageSize = myPageSize;
  int recordCount = retrieveRecordCount();
  if (pageStart + pageSize > recordCount)
    pageSize = recordCount - pageStart;
...
}


The same approach with explicit binding of data parameters is applicable for sorting and filtering parameters. Feel free to ask if you need help with implementing this approach.

Regards,
Dmitry