6 Replies Latest reply on Jan 10, 2009 11:34 AM by nimo stephan

    dataScroller for ScrollableResults or ServerSide-Paginations

    nimo stephan Master

      I want to use Paginations via ScrollableResults
      or via setMaxResults,setFirstResult.

      The actual Resultlist is viewed in a rich:dataTable,
      which has a rich:dataScroller.

      The rich:dataScroller considers only the actual Resultlist.

      When I scroll for example via ScrollableResults,
      then my rich:dataScroller changes the page-numbers. (That means, it does not show the absolute number of pages).

      So the rich:dataScroller is not suitable for Server-Side-Paginations.
      Am I right?

      Should I provide conventional links (page1, page2,next,...)
      instead of using the component rich:datascroller ?

      Any suggestions?

        • 1. Re: dataScroller for ScrollableResults or ServerSide-Paginat
          nimo stephan Master

          When I do something like:

          Query q = session.createQuery("from Items i");
          q.setMaxResults(500);
          q.setFirstResult(0);
          List items = q.getResultList();


          and put the items-List into a rich:dataTable (without using rich:datascroller):

          <rich:dataTable value="#{myBean.items}" var="i">
          ..


          then I get my result via this generated sql:

          select
           *
           from
           ( select
           rownumber() over() as rownumber_,
           items0_.ID_ITEM as ID1_414_,
           ...
           from
           ITEMS items0_ ) as temp_
           where
           rownumber_ between ?+1 and ?


          That works fine.

          But I found out, that when using rich:dataScroller with rich:dataTable:

          <rich:dataTable value="#{myBean.items}" var="i" rows="500">
          <rich:datascroller ...>


          the datatable also only fetch 500 rows (and not all rows).
          Does it mean, that the rows-Attribute does internally do something like q.setMaxResults(500) ?

          Does the rich:datatable use "setMaxResults" internally,
          when rows-Attribute is set?






          • 2. Re: dataScroller for ScrollableResults or ServerSide-Paginat
            nimo stephan Master

            Having a look in the sourceCode of dataScroller,
            it seems, that it calls iterate().

            Would it be not better (for performance),
            to use sexMaxResult, setFirstResult in order to fetch a bunch of data?

            Is ScrollableResults faster than sexMaxResult, setFirstResult and iterate() ?

            I want to call 5000 rows at once within a page using a paginator (rich:datascroller). For example, by clicking to the datascroller-item '2', the next 5000 rows should be loaded. What is best practice for such scenarios? Using the build-in-iterator() of rich:dataScroller or using the sexMaxResult or using ScrollableResults and build a datascroller via links?

            Any experiences?

            • 3. Re: dataScroller for ScrollableResults or ServerSide-Paginat
              Nick Belaevski Master

              Hello,

              Datascroller uses getRowCount() method of UIData class that in turn refers to DataModel#getRowCount(). Implementation of this method is model-specific and component is not aware of the details. Component's job is just to set rowIndex sequentially while rows exists and number of fetched rows is less then number of rows to show. So there's no place for setMaxResult method in standard JSF.

              ExtendedDataModel that is supported by rich:dataTable out of the box provides more convenient way of fetching data: there's walk(FacesContext context,DataVisitor visitor,Range range, Object argument) method that accepts instance of Range class as parameter. Typical implementation of Range class contains information about the first row and the number of rows to fetch. If you know the limit for amount of pages datascroller displays then you can implement getRowCount() method in more efficient way. Note: this may not work for data table sorting and filtering feature.

              P.S. Some links that may be useful: http://www.hibernate.org/248.html
              http://www.hibernate.org/314.html

              P.P.S. We've also got RFC for manually setting number of datascroller pages: https://jira.jboss.org/jira/browse/RF-5479

              • 4. Re: dataScroller for ScrollableResults or ServerSide-Paginat
                nimo stephan Master

                ExtendedDataModel sound good..

                you say

                ExtendedDataModel that is supported by rich:dataTable


                you mean ..supported by rich:extendedDataTable, not rich:dataTable. Am I right?

                Exists any examples of using the "walk(FacesContext context,DataVisitor visitor,Range range, Object argument)" method ?

                Where can I found examples of using the walk-Method?

                Assume, I use that walk-method. Does the acorresponding rich:dataScroller adapt to this rich:extendedDataModel accordingly when using walk-Method?

                Thanks for the link http://www.hibernate.org/248.html http://www.hibernate.org/314.html. That helped me.
                The pagination-example uses ScrollableResults.

                Besides, do you know what is faster:
                Is ScrollableResults faster than sexMaxResult, setFirstResult and iterate()? Should I always prefer ScrollableResults (when supported) for better performance instead of sexMaxResult?








                • 5. Re: dataScroller for ScrollableResults or ServerSide-Paginat
                  Nick Belaevski Master

                   

                  you mean ..supported by rich:extendedDataTable, not rich:dataTable. Am I right?

                  All iteration components in Richfaces support ExtendedDataModel class (some components support more specialized implementations of this class, e.g. rich:tree). a4j:repeat and rich:dataTable components support ExtendedDataModel out of the box either as rich:extendedDataTable component (see hierarchy of org.ajax4jsf.component.UIDataAdaptor class for more information, pay attention to getDataModel()/createDataModel() methods).

                  Exists any examples of using the "walk(FacesContext context,DataVisitor visitor,Range range, Object argument)" method ?

                  Where can I found examples of using the walk-Method?

                  http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=dataModel -> View AuctionDataModel.java Source

                  BTW, you can see fully-functional rich:datascroller component at this demo.

                  Besides, do you know what is faster:
                  Is ScrollableResults faster than sexMaxResult, setFirstResult and iterate()? Should I always prefer ScrollableResults (when supported) for better performance instead of sexMaxResult?


                  Googling gives some useful information on this: http://forums.hibernate.org/viewtopic.php?p=2287056&sid=b8b08c878f0da94680f0bf239b6bca14
                  http://www.redhat.com/docs/en-US/JBoss_Enterprise_Application_Platform/4.3.0.cp03/html/Hibernate_Reference_Guide/Working_with_objects-Querying.html#Querying-Executing_queries - see 10.4.1.6. Scrollable iteration there

                  I would advise you to ask this question at more specialized forums like Hibernate.

                  • 6. Re: dataScroller for ScrollableResults or ServerSide-Paginat
                    nimo stephan Master

                    thank you :-)

                    Thats exactly what I was searching for.