13 Replies Latest reply on Apr 8, 2011 7:04 AM by apostle

    Handle large data sets with RichFaces 4

    apostle

      Hi dear community,

       

      I'm looking for the description how to work with large data sets. To be more exact I need server-side pagination implementation. 

       

      I found an example how to do it here http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=dataModel&cid=3608154, but it is for richfaces 3.3.3 I also found some posts on the forum, but they all about version 3.3.3 and it looks like the discussed solutions cant be used for Richfaces 4.

       

      Could someone please point me on an appropriate place in documentation or the best practice pages if any or give me a hint from where I have to start.

       

      Thanks,

      Pavel

        • 1. Handle large data sets with RichFaces 4
          boy18nj

          use rich:datascroller for pagination.

          • 2. Handle large data sets with RichFaces 4
            apostle

            Aman,

            thanks for your interest.

            I guess I was not clear enough. My problem is:

            In case a table contains 100 000 - 200 000 records, it is not a good idea to load all records at a time. If I'm not mistaken rich:datascroller does pagination on client side(at least by default). In this case all records will be loaded during dataTable initialisation. What I want is to make data loading for the current page only and once user moves to the next page, the next portion of data needs to be loaded. Unfortunatly, I cannot find a way how to make it work.

             

            Pavel

            • 3. Handle large data sets with RichFaces 4
              boy18nj

              what framework you are using on the server side like Seam and ORM framework like hibernate?

              • 4. Re: Handle large data sets with RichFaces 4
                luca.graf

                Hi Pavel,

                 

                you must extend org.ajax4jsf.model.ExtendedDataModel.

                 

                edit:

                basic example: http://pastebin.com/a9Qs4xVT

                 

                Message was edited by: Luca Graf

                • 5. Handle large data sets with RichFaces 4
                  apostle

                  to Aman S

                  I use EJB3/JPA/Hibernate on server-side

                   

                  to Luca Graf

                  Hi Luca,

                  Thank you very much. That's it. Unfortunately, I did not find it myself.

                   

                  Thank you guys for your help.

                  • 6. Re: Handle large data sets with RichFaces 4
                    boy18nj

                    check out this full blown example-

                     

                    http://katzmaier.blogspot.com/2010/03/richfaces-server-side-pagination.html

                     

                    replace SerializableDataModel with ExtendedDataModel and necessary refactoring. Since in Richfaces 4, SerializableDataModel  class no longer exists.

                     

                    Normally I won't prefer to extend these richfaces classes to implement pagination. I would recommend to implement pagination using EJB3 and Hibernate and call them from richfaces. As this solution would even help you in scenario's where you want to implement pagination in EJB/Hibernate only.

                    • 7. Re: Handle large data sets with RichFaces 4
                      apostle

                      Aman,

                      have I got  you right that I can implement pagination with Hibernate and EJB only? Would you, please, explain in a bit more details how I can do it. I clearly understand how to get appropriate data from database, but I'm  wondering how JSF page would look like in this case. I thought that I would have to extend ExtendedDataModel to implement this behaviour even if I use Hibernate to get portioned out data. Am I wrong?

                       

                      Thanks

                      • 8. Re: Handle large data sets with RichFaces 4
                        iabughosh

                        Dear Pavel,

                        try this example, this example from Pro JPA 2

                         

                        @Stateful

                        public class ResultPagerBean implements ResultPager {

                        @PersistenceContext(unitName="QueryPaging")

                        private EntityManager em;

                        private String reportQueryName;

                        private long currentPage;

                        private long maxResults;

                        private long pageSize;

                         

                        public long getPageSize() {

                        return pageSize;

                        }

                        public long getMaxPages() {

                        return maxResults / pageSize;

                        }

                        public void init(long pageSize, String countQueryName,

                         

                        String reportQueryName) {

                         

                        this.pageSize = pageSize;

                        this.reportQueryName = reportQueryName;

                        maxResults = em.createNamedQuery(countQueryName, Long.class)

                        .getSingleResult();

                        currentPage = 0;

                        }

                         

                        public List getCurrentResults() {

                        return em.createNamedQuery(reportQueryName)

                        .setFirstResult(currentPage * pageSize)

                        .setMaxResults(pageSize)

                        .getResultList();

                        }

                        public void next() {

                        currentPage++;

                        }

                         

                        public void previous() {

                        currentPage--;

                        if (currentPage < 0) {

                        currentPage = 0;

                        }

                        }

                         

                        public long getCurrentPage() {

                        return currentPage;

                        }

                        public void setCurrentPage(long currentPage) {

                        this.currentPage = currentPage;

                        }

                        @Remove

                        public void finished() {}

                        }

                        • 9. Re: Handle large data sets with RichFaces 4
                          apostle

                          Dear Ibrahim,

                          thank you for helping me out. As I previously mentioned it is not a problem to me to get portioned out data from a database using EJB/JPA. I'm having troubles with JSF page implementation for that kind of bean. Could you please post an example of JSF with rich:dataTable component which shows data using the bean you provided in your post. In case of your bean, for instance, how I can get rich:dataTable known that once user clicks 'next page' button on rich:dataScroller it should increase 'currentPage' variable and return next portion of data. Thanks

                          • 10. Re: Handle large data sets with RichFaces 4
                            ilya_shaikovsky
                            I found an example how to do it here http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=dataModel&cid=3608154, but it is for richfaces 3.3.3 I also found some posts on the forum, but they all about version 3.3.3 and it looks like the discussed solutions cant be used for Richfaces 4.

                             

                            It's better to check Modifiable Model sample actually. It contains more cool sample of generic model with concrete implementation for the concrete data object. And it handles not only pagging at db level but only sorting and filtering using Criteria's. B.t.w. I missed to add sources properly to livedemo so it's better to checkout from svn in order to explore base model class. http://www.jboss.org/richfaces/demos

                             

                            As for migration to 4.x - It's should be not problematic. I not migrated sample just because lack of time but all you need to move from 3.3.x ModifiableModel (modify() method in Modifiable interface) to very similar 4.x ArrangeableModel (arrange method in Arrangeable interface)

                            • 11. Re: Handle large data sets with RichFaces 4
                              apostle

                              Ilya,

                              thanks for clarification. It is really helpful.

                              I've looked through the example made with RichFaces 3.3.3 and found that it is created with seam framework. I'm wondering if it is possible to do the same with JSF 2  without using seam? Could you please, share your ideas regarding it. Thanks.

                              • 12. Re: Handle large data sets with RichFaces 4
                                ilya_shaikovsky

                                you could use anything you want to load actual data. That sample just designed to show how our model methods contract are used with hibernate. You should perform basically the same but for any other for sure.

                                • 13. Re: Handle large data sets with RichFaces 4
                                  apostle

                                  Thanks for your help, Ilya.

                                  Just did it and was going to post here that I found the answer.