views:

1728

answers:

7

I have a JSF application that I am converting over to use webservices instead of straight up database queries. There are some extremely long lists that before could be returned easily with a simple SQL query. I'd like to figured out how implement the paging using JSF/web services. Is there a good design pattern for doing paged web services?

If it matters, I'm currently using the Apache MyFaces reference implementation of JSF with the Tomahawk extensions (a set of JSF components created by the MyFaces development team prior to its donation to Apache).

+2  A: 

I like Seam's Query objects: http://docs.jboss.com/seam/2.1.0.BETA1/reference/en-US/html_single/#d0e7527

They basically abstract all the SQL/JPA in a Seam component that JSF can easily use.

If you don't want to use Seam and/or JPA you could implement a similar pattern.

Sietse
+2  A: 

Trinidad has a table component that supports paging, which may help. It is not ideal, but works well enough with Seam, as described in Pete Muir's Backing Trinidad's dataTable with Seam blog post.

If you don't find a JSF component you like, you'll need to write your own logic to set parameters for limit and offset in your EJB-QL (JPA) queries.

Peter Hilton
+1  A: 

All of the answers seem geared towards using EJB/JPA which have database access. The database I'm getting my data from now is going away, and I need to use webservices... any more help out there?

Alex Argo
You could use the same pattern, but with different backing. I'm not sure if there are any off-the-shelf solutions though. If you want more answers, I suggest posting a new question.
Sietse
this answer is not an answer :-S
Simon Gibbs
+2  A: 

It depends on whether you want to do client-side or server-side paging. If server side, your web services will have to include a couple of additional parameters (e.g. "startFrom" and "pageSize") which will let you specify which 'page' of the data to retrieve. Your service will probably also need to return the total result size so you can generate a paging control.

If you decide that's too much effort you can do client-side paging in your backing bean (or get a component to do it for you), however it's not recommended if you're talking about thousands of objects!

Phill Sacre
+2  A: 

We used the RichFaces library Datatable: http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=usage

It's quite simple, and if you're not using RichFaces already, it's really easy to integrate with MyFaces.

bwobbones
+1  A: 

If you are getting all the results back from the webservice at once and can't include pagination into the actual web service call, you can try setting the list of items to a property on a managed bean. Then you can hook that up to the "value" attribute on a Tomahawk dataTable:

http://myfaces.apache.org/tomahawk-project/tomahawk/tagdoc/t_dataTable.html

and then you can use a Tomahawk dataScroller to paginate over the list of items stored in that property. Here is the reference for that component, it works well with the dataTable component:

http://myfaces.apache.org/tomahawk-project/tomahawk/tagdoc/t_dataScroller.html

You can include this inside the header/footer facets of the dataTable or as a separate compoment (you will need to specify the id of the dataTable in the 'for' attribute of the dataScroller.

There's other neat things you can do with the dataTable like sorting and toggling details for each row, but that can be implemented once you get the basic pagination working.

Hope that helps!

A: 

Seems like Alex knew how to fix it with a database. The problem is how to solve it with a webservice.

If I had enough reputation I guess I'd downvoted a couple of the answers above for that reason.

Erik Itland