4 Replies Latest reply on Jan 26, 2007 11:31 AM by Dan Liu

    pagination problem, advice needed

    Dan Liu Apprentice

      I've been trying to solve this problem for ages but still couldn't find a good solution. I have an entity which looks like this:

      class Person{
      String name;
      int age;
      List<Review> reviews;
      List<Call> calls;
      }
      


      in my jsf page, I have:
      <h:outputText value="person.name" />
      <h:outputText value="person.age" />
      <h:dataTable value="person.reviews" var="review" rows="5">
      ...
      </h:dataTable>
      
      <h:dataTable value="person.calls" var="call" rows="5">
      ...
      </h:dataTable>
      
      


      both reviews and calls need to have their own page control because there can be more than 1000 rows.

      The ideal way to do this is to have a scroller component that is similar to t:dataScroller, but only load the required data rows from database each time when change the page. However, this component doesn't exist in this world. Without such a component, I would have to write customised HSqls for each entity and write my own scroller component. Since I have a lot of entities that are similar to this one, it's so time consuming to do it this way. Can someone give any advice what would be the easiest way to solve this problem?


      Also, I have another question, is there anyway to limit the number of returning rows when define @OneToMany relationship. e.g. @OneToMany(fetch=FetchType.EAGER, maxNumberOfRows=10) ?



        • 1. Re: pagination problem, advice needed
          Gavin King Master

          t:dataScroller is absolutely the wrong way to do it - as you've noticed, it means loading a massive result set into memory just to display a few items. I've seen lots of JSF controls like this - written by people who think too much about the GUI and not enough about data access. This is a major problem in the web framework space. One of the reasons Seam is so different to other web frameworks is that we took all our Hibernate experience into account when designing it.

          So, the way to do it in Seam is to use Query pagination. Check out the contactlist example, and this documentation:

          http://docs.jboss.com/seam/1.1BETA2/reference/en/html/framework.html#d0e6595

          • 2. Re: pagination problem, advice needed
            Dan Liu Apprentice

            Thanks Gavin. I've had a look at Query and it looks great. However, my situation is a bit more complicated. What I need is a way to to paginating the collocation based property of my entities. Here is my code:

            <h:dataTable value="#{persons}" var="person" >
             <h:outputText value="#{person.name}" />
             <h:outputText value="#{person.age}" />
             <h:dataTable value="#{person.reviews}" var="review" >
             <h:outputText value="#{review.title}" />
             </h:dataTable>
            
             <h:dataTable value="#{person.calls}" var="call" >
             <h:outputText value="#{call.duration}" />
             </h:dataTable>
            <h:dataTable>
            


            As you can see, Query is good for paginating #{persons}. But for #{person.reviews}, I don't see a easy way of doing it. I have many entities that require this kind of multi-level pagination. Can you give any advices on this? Thanks

            • 3. Re: pagination problem, advice needed
              Gavin King Master

              You want to paginate a table inside another table???!

              I have never seen this done in any user interface in my life.

              Sounds like a bad idea.

              Anyway, I'm sure you could very easily do this by following the patterns used in the Query class.

              • 4. Re: pagination problem, advice needed
                Dan Liu Apprentice

                Sorry I was trying to explain my situation better but made it worse. Here is my scenario. The person.xhtml page shows all the properties of Person entity. In this page, I need to show top 5 records of person's calls and reviews. Here is the code:

                <h:outputText value="#{person.name}" />
                 <h:outputText value="#{person.age}" />
                 <h:dataTable value="#{person.reviews}" var="review" >
                 <h:outputText value="#{review.title}" />
                 </h:dataTable>
                
                 <h:dataTable value="#{person.calls}" var="call" >
                 <h:outputText value="#{call.duration}" />
                 </h:dataTable>
                


                Paginating for {person} is easy when using Query. but to paginating for {person.reviews} and {person.calls} is not easy. By now, I have to create a pagination object for each collection based property. If Person has 4 collection type properties (e.g. calls,reviews...), I basically have to create 4 extra pagination objects with customised Hsqls for pagination. It's so time consuming to do it this way. If I use t:dataScroller, I wouldn't have to create those 4 extra objects. But as you said, there's performance problem with t:dataScroller. It would be nice if Seam can provide a s:dataScroller, which support real database based pagination.