2 Replies Latest reply on Dec 13, 2006 12:42 PM by gavin.king

    EntityQuery pagination

    rsmol

      Hello, I'm quite new to JSF and Seam. I've followed docs and using seam-gen I've managed to generate entities and frontend for them. Now I have class LogsList that extends EntityQuery. It works fine, however I would like provide user with possibility to change the results per page.

      Generated class has method getMaxResults() and hard coded 25 in it. It seems that EntityQuery is stateless? After changing set/get methods for maxResults I do not know how to provide initial value (there are 1M+ entries in DB). I can't do that as there is @Create annotated method validate and this one is used every time I refresh results. When I Override the method it seems that

      if(getMaxResults() == null) {setMaxResults(25)}
      


      condition always pass. In the LogsList.xhtml (section tableControl) I've provided:
      <h:selectOneMenu value="#{logsList.maxResults}" id="maxResults">
       <f:selectItem itemLabel="5" itemValue="5"/>
       <f:selectItem itemLabel="10" itemValue="10"/>
       <f:selectItem itemLabel="20" itemValue="20"/>
      </h:selectOneMenu>
      

      And I though that when I click next page, the currently selected valued is assigned to logsList and then proper number of records should be displayed. What am I missing? Or shall I uses statefull object like "settings" to store such an information?

      I've managed to achieve this using Statefull EJB, but I'would love to use this EntityQuery object. I've digged through the source code of examples (great way of inspiration) but they either use Statefull EJB or functionality is not provided. I would also like to restrict search with some restrictions.
      Can anybody give me any hints? I might be confused of when to use @In and when/how use setters of property.





        • 1. Re: EntityQuery pagination

          Are you asking how to make your event scoped query be conversation/session scoped like a stateful component? If so, look at the @Scope annotation. (or the scope attribute on the xml)

          If you want to stay in the EVENT scope with your query, try adding using a more dynamic value. This works best from components.xml: max-results="#{someSessionObject.maxResults}"

          Or, you could add the max results as a request paramter:

           <page view-id="/search.xhtml">
           <param name="howmany" value="#{yourQuery.maxResults}" />
           </page>
          


          I'm not sure what way fits your app best.



          • 2. Re: EntityQuery pagination
            gavin.king

            Why not just call setMaxResults in the constructor? Or, you can override the @Create method and do it there.