Joao Bortoletto wrote:
Hi Alexander,
Thanks for your response!
I've studying the example source code. It works
fine but, like you said, I'm trying to do special
things... here we go:
I have a system that access data by oracle stored
procedures.
My team decided that data must be paginated on
database to avoid excessive web server memory usage.
So, stored procedures receive a given page as
parameter and return records based on that page.
So, I'd like to have an engine that calls a given
stored procedure to get data for a given page on each
pagination request.
I was trying to do that writing a custom
javax.faces.model.DataModel... but it appears hard...
It is not that hard, although not too easy thanks to the overcomplicated
api, the main problem you face by implementing your own DataTable is to
have clear demarkation points on when you can aquire the DB resources
and when you can release them, there is simply no mechanism defined to
achive that.
Currently there are several ways known to me:
a) you can prefetch a page and serve the data from an internal cache
(which is the approach I follow currently)
b) you can use some kind of interceptor/filter on the servlet, which
notifies the datamodel of the beginning of the request and the end of
rendering, so that you can do the resource management.
There are currently several solutions preimplemented which can achieve
exactly that:
In Spring you have the OpenSessionInViewFilter class/interface
and in Shale the ViewController Interface also can solve the problem.
Also using ViewStateListeners on the first and last state of the refresh
cycle which notify any models currently in existence might work as well,
very elegantly.
The rest is more or less implementing the mechanisms, which are defined
by the base classes.
Approach a) might be the hardest of all, because adding a caching layer
to the datamodel, adds another dimension of complexity, if I had to do
it again, I probably ould use approach b) which was unknown to me when I
did a)