0 Replies Latest reply on Sep 3, 2008 3:23 PM by Adam Warski

    AJAX paging of data

    Adam Warski Master

      Hello,


      Assume that I have a large dataset in the database. I want to implement AJAX-scrolling through that dataset, so that only the data that should be displayed is loaded from the DB.


      Using GET requests, that would be simple, as I would just need a page with a from attribute, which would specify from which row to show the data. However, I want to use AJAX :)


      My first try was to use RichFaces dataTable and datascroller, but, it's not so easy (see here). I guess it can be made to work, but seems overly complicated and heavy, while I only need to display a next and previous link plus a list of strings (so ui:repeat is enough).


      The other solution is to have a PAGE-scoped component that holds a from variable, and make next an action link, which increases the from variable. The bean survives all the ajax refreshes, as the ajax requests don't create a new view root.


      And this works, but there are some drawbacks.


      If the list of entities read from the database is cached also in that page-scoped bean (and cleared whenever next is clicked), then it gets stored in the session, which unnecessarily increases memory usage.


      If the list of entities is cached in an event-scoped bean, then the datbase is queried twice on every request: once for the old from value (when the view is restored), once for the new one (when the view is rendered).


      Of course, the ideal solution would be to store only from in the page-scoped bean, and read only once from the database. Is that possible?


      Adam