4 Replies Latest reply on Aug 1, 2008 5:11 AM by Daniel Soneira

    Datascroller and true pagination

    Franco Fernandes Novice

      Hi

      I am desperate here, I have been stuck on this for the last 2 weeks - I have time to kill right now but this is killing me :(

      I did some custom changes with seam-gen to create an template with Richfaces datascroller for every list page. The problem I discovered later was that the datascroller was not really doing a true pagination and firing the entire query for every "next" page. Very costly, not something I would ever put in production and have a good night's sleep.

      I am a newbie to Seam/Hibernate/Richfaces but not new to J2EE stuff.

      This was perhaps a challenge I am not ready for yet. But I decided to give it a shot. I started looking at using a custom SerializableDataModel and found these many helpful posts on this topic.

      http://www.seamframework.org/docDisplay_d.seam
      http://eclecticprogrammer.com/2008/06/25/sorting-and-paginating-in-the-database-with-richfaces/


      I used the approach documented in the latter post. Worked very well, with sorting too. But I had to be put my the datamodel in session scope for it to work.

      I then encountered another issue - after a new search, the datascroller would not get reset. Let's say my first search gave me 20 rows and I had 10 rows per page, that would be 2 pages. when I did a new search resulting in either no data or 1 page of data, I would still see 2 pages.

      Then I followed this
      http://jboss.com/index.html?module=bb&op=viewtopic&t=127277

      and bound my datascroller to my data table.

      @Name("burstDataModel")
      @Scope(ScopeType.SESSION)
      public class BurstDataModel extends SerializableDataModel {
      ---
      ---
      
       @In(required=false)
       private BaseUIDatascroller datascrollerUI = null;
      ---
      ---
       public void search () {
       update();
      
       datascrollerUI.getDatascroller().getDataTable().setFirst(0);
       }
      
      
      }
      


      Search action would then call search method on datamodel above. Still no luck, the datascroller does not reset as expected.

      The richfaces developers have put up a nice example how to do pagination using the extended data model. But it is in no way complete.

      Then there are the critics of using the datascroller at all.
      http://jboss.com/index.html?module=bb&op=viewtopic&t=139916
      http://www.seamframework.org/Community/TroublesToUseDatascrollerAndExtendedDataModel

      I implemented the Facelets tag in the 2nd post and it works great!

      Then this guy shows how to reset the UIData in the model
      http://solutionsfit.com/blog/2007/11/13/solution-using-seam-to-pagination-issue-with-jsf-on-datamodel-updates/

      I did not try it, too raw for this stuff.


      Richfaces developers:

      Can you answer these questions ?
      --------------------------------------------------------------------------------
      Can the datascroller along with an extended model support true pagination ?
      What scope should this model lie in ? -
      session ? - overkill conversation - when should you start/stop the conversation ?
      What scope should the data provider be in ?
      How do you sync the datascroller to the data in the extended model ?
      Is it not possible to have true paging built into the control itself ?
      --------------------------------------------------------------------------------


      I do not give up easily, but frankly I think I may have to concede defeat here!


      Is there anyone who can post a complete working example for newbies ?


      Thanks
      Franco





        • 1. Re: Datascroller and true pagination
          Franco Fernandes Novice

          Sorry to bump this up.

          Can anyone share their experience with the datascroller component.

          Thanks,
          Franco

          • 2. Re: Datascroller and true pagination
            Daniel Soneira Novice

            In RichFaces 3.1.6 / 3.2.1 the datascroller should automatically reset to the first page if the model changes.

            Which version are you using?

            • 3. Re: Datascroller and true pagination
              Franco Fernandes Novice

              I am using version 3.2.1

              Perhaps the key then for me is understanding the sequence of steps when a new search is executed. In my code, here I just call

              <h:commandButton value="Find" action="#{burstDataModel.search}" />
              


              Methods in extended datamodel

               public void search () {
               update();
              
               datascrollerUI.getDatascroller().getDataTable().setFirst(0);
               }
              
              
               @Override
               public void update() {
               if (getSortFieldObject() != null) {
               String newSortField = getSortFieldObject().toString();
               if (newSortField.equals(sortField)) {
               descending = !descending;
               }
               sortField = newSortField;
               }
               detached = false;
               }
              
              
              
              
              Based on the documentation I have read, after update(), detached is set to false and triggers wrappedKeys to be rebuilt from the dataprovider.

              Have you used this successfully?
              with EntityQuery ?

              What scope do I put these in ?

              Thanks for your response.
              Franco



              • 4. Re: Datascroller and true pagination
                Daniel Soneira Novice

                To be honest - I'm using "standard" jsf managed beans and don't have a clue about Seam.

                In my case a simple replacement of a list (which is used for the table/datascroller) does the trick:

                Similar to the code below

                JSP

                
                 <h:commandButton action="${controller.handleSearch}"/>
                 <a4j:repeat id="resultTable" value="${model.resultList}" var="result">
                 ...
                 </a4j:repeat>
                
                 <rich:datascroller for="resultTable"/>
                


                Controller (request scope)
                public void handleSearch {
                 log().debug("handleSearch");
                 model.setResultList(service.getEntitiesByFilter(model.getFilter()));
                }
                


                Model (session scope)
                private Entity filter;
                private List<Entity>resultList;
                
                public List<Entity> getResultList() {
                 return resultList;
                }
                
                public void setResultList(List<Entity> resultList) {
                 this.resultList = resultList;
                }
                
                public Entity getFilter() {
                 return filter;
                }
                
                public void setFilter(Entity filter) {
                 this.filter = filter;
                }