4 Replies Latest reply on Dec 14, 2007 11:27 AM by supernovasoftware.com

    @Factory & Pagination

    skanky78

      hi folks,

      i 've read many post in this forum but i didn't find an answer to my specific issue. I'm trying to do pagination together within the method annotated with @Factory. I tried the rich:dataScroller control and some other things like custom page links with params but i didn't get the pageindex of the requested page (if user paginates to another site). i need it in this method to fetch the items for the selected page. how could do that?

      ps: i've tried request params but i always got null:(


      
      class:
      
      @Factory("items")
      public List findItems() {
      
       ....use buisness method th retrieve items for listview
      
      }
      
      facelet:
      
      <rich:dataTable value="#{items} var="item" rows="10"...>
      ...
      </rich:dataTable>
      
      


      thanks in advance,
      sven

        • 1. Re: @Factory & Pagination
          andygibson

          Hey Sven,

          Well, here's the problem, the factory method needs to know what page you are on, and then return the results for that page.

          The first easy option is to use an EntityQuery which has the firstResult and maxResults, next, first, last, previous and a bunch of other properties and methods to let you control the data.

          You can roll your own, but then you find yourself writing a bunch of code that is the same as the existing EntityQuery object code.

          The problem with the rich:dataScroller is that it works on the whole list at once. The EntityQuery queries the database for the number of rows in the result, and then only fetches the number of rows on a page.

          You can set up params in pages.xml to pass from one page to the next the values of the current page so you have a stateless viewer as opposed to keeping all items in memory (or keep reloading them) for the data scroller.

          Cheers,

          Andy






          • 2. Re: @Factory & Pagination

            Note: EntityQuery requires JPA, so if you're just using plain Hibernate (like me) you might be out of luck :(.

            • 3. Re: @Factory & Pagination
              andygibson

              You could roll your own non-JPA entity query which woudl have methods for pagination. It's probably well worth it considering the re-use you can get out of them. Same with EntityHome.

              Cheers,

              Andy

              • 4. Re: @Factory & Pagination

                I just posted an example of Ajax paging with Richfaces Datascroller

                http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4112998#4112998