<p>I have a <a href="http://en.wikipedia.org/wiki/JavaServer_Faces" rel="nofollow noreferrer">JSF</a> application that I am converting over to use webservices instead of straight up database queries. There are some extremely long lists that <em>before</em> 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?</p>

<p>If it matters, I'm currently using the <a href="http://en.wikipedia.org/wiki/Apache_MyFaces" rel="nofollow noreferrer">Apache MyFaces</a> 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).</p>

[{'answer_id': 70046, 'author': 'Sietse', 'author_id': 6400, 'author_profile': 'https://Stackoverflow.com/users/6400', 'pm_score': 2, 'selected': False, 'text': '<p>I like Seam\'s Query objects: <a href="http://docs.jboss.com/seam/2.1.0.BETA1/reference/en-US/html_single/#d0e7527" rel="nofollow noreferrer">http://docs.jboss.com/seam/2.1.0.BETA1/reference/en-US/html_single/#d0e7527</a></p>\n\n<p>They basically abstract all the SQL/JPA in a Seam component that JSF can easily use.</p>\n\n<p>If you don\'t want to use Seam and/or JPA you could implement a similar pattern.</p>\n'}, {'answer_id': 70048, 'author': 'Peter Hilton', 'author_id': 2670, 'author_profile': 'https://Stackoverflow.com/users/2670', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://myfaces.apache.org/trinidad/" rel="nofollow noreferrer">Trinidad</a> 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 <a href="http://pmuir.bleepbleep.org.uk/2007/04/backing-trinidads-datatable-with-seam.html" rel="nofollow noreferrer">Backing Trinidad\'s dataTable with Seam</a> blog post.</p>\n\n<p>If you don\'t find a JSF component you like, you\'ll need to write your own logic to set parameters for <em>limit</em> and <em>offset</em> in your EJB-QL (JPA) queries.</p>\n'}, {'answer_id': 73104, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>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.</p>\n\n<p>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!</p>\n'}, {'answer_id': 78994, 'author': 'bwobbones', 'author_id': 213719, 'author_profile': 'https://Stackoverflow.com/users/213719', 'pm_score': 2, 'selected': False, 'text': '<p>We used the RichFaces library Datatable: <a href="http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=usage" rel="nofollow noreferrer">http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=usage</a></p>\n\n<p>It\'s quite simple, and if you\'re not using RichFaces already, it\'s <strong>really</strong> easy to integrate with MyFaces.</p>\n'}, {'answer_id': 96007, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>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: </p>\n\n<p><a href="http://myfaces.apache.org/tomahawk-project/tomahawk/tagdoc/t_dataTable.html" rel="nofollow noreferrer">http://myfaces.apache.org/tomahawk-project/tomahawk/tagdoc/t_dataTable.html</a></p>\n\n<p>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:</p>\n\n<p><a href="http://myfaces.apache.org/tomahawk-project/tomahawk/tagdoc/t_dataScroller.html" rel="nofollow noreferrer">http://myfaces.apache.org/tomahawk-project/tomahawk/tagdoc/t_dataScroller.html</a></p>\n\n<p>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. </p>\n\n<p>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. </p>\n\n<p>Hope that helps!</p>\n'}]
['https://Stackoverflow.com/questions/69917', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5885/']