RE: Pagination query

From: Laszlo Spoor (lspoor_cayenn..otmail.com)
Date: Thu Feb 10 2005 - 15:51:09 EST

  • Next message: Sami Mohammed: "RE: Pagination query"

    Hi Sami,

    Well, the bean I have provided will take a pCurrentRow as a parameter, so
    when you (re)enter the JavaBean or Servlet responsible for retrieving the
    data, be sure to use next 'pCurrentrow'. This functionality is also provided
    in the PagedObjectList, as in the method getNextSet() or getPreviousSet().

    Say, you use Struts, in your 'populateAction', you can use:

       // Retrieve Complex Subset
        ComplexHandler cpxh = new
    ComplexHandlerImpl(DataContext.getThreadDataContext());
        ComplexList cpxList =
    cpxh.getAllPaged(BackOfficeReferences.IMG_DEF_PAGE_LENGTH, newRow);
        request.setAttribute(ComplexList.CLASS_NAME, cpxList);

        // Populate pager
        // Previous ResultSet
        Boolean hasPrev = new Boolean(cpxList.hasPreviousSet());
        request.setAttribute("hasPrevious", hasPrev);

        HashMap m1 = new HashMap();
        m1.put("curRow", new Integer(cpxList.getPreviousSet()));
        request.setAttribute("prevSet", m1);

        // Next ResultSet
        Boolean hasNext = new Boolean(cpxList.hasNextSet());
        request.setAttribute("hasNext", hasNext);

        HashMap m2 = new HashMap();
        m2.put("curRow", new Integer(cpxList.getNextSet()));
        request.setAttribute("nextSet", m2);

        // Remember the current row.
        request.setAttribute("curRow", curRow == null ? "0" : curRow);

    Now, you can retrieve the previous and next record sets, using a
    construction like:

    ..taglib uri="/tags/struts-bean" prefix="bean" %>
    <..taglib uri="/tags/struts-html" prefix="html" %>
    <..taglib uri="/tags/struts-logic" prefix="logic" %>
    <..taglib uri="/tags/struts-tiles" prefix="tiles" %>

    <%-- Retrieve the url needed for paging from the Tiles template --%>
    <tiles:useAttribute name="url" classname="java.lang.String"/>

    <%-- Previous --%>
    <logic:equal name="hasPrevious" value="true">
      <html:link page="<%=url%>"
                 name="prevSet">
         <bean:message key="bfe.pager.previous"/>
      </html:link>
    </logic:equal>

    <logic:equal name="hasPrevious" value="false">
      <bean:message key="bfe.pager.previous"/>
    </logic:equal>

    <%-- Next --%>
    <logic:equal name="hasNext" value="true">
      <html:link page="<%=url%>"
                 name="nextSet">
        <bean:message key="bfe.pager.next"/>
      </html:link>
    </logic:equal>

    <logic:equal name="hasNext" value="false">
      <bean:message key="bfe.pager.next"/>
    </logic:equal>

    Hope this helps, laszlo

    here you have my .jsp that

    >From: "Sami Mohammed" <SMOHAMME..ndependenthealth.com>
    >Reply-To: cayenne-use..bjectstyle.org
    >To: <cayenne-use..bjectstyle.org>
    >Subject: RE: Pagination query
    >Date: Thu, 10 Feb 2005 15:20:49 -0500
    >
    >Hi Laszlo,
    >I am also using the struts tag libs, but how can we show the next and
    >previous pages links on the jsp.
    >
    >
    > >>> lspoor_cayenn..otmail.com 02/10/05 03:00PM >>>
    >Hi Sami,
    >
    >How you display the results on your JSP depends on what technology you use.
    >I normally use Jakarta tag libraries
    >(http://struts.apache.org/userGuide/index.html).
    >
    >For example:
    >
    ><logic:iterate id="painting" name="ptgList">
    > <bean:write name="painting" property="toArtist.name"/>
    ></logic:iterate>
    >
    >
    >Regards, laszlo
    >
    >
    > >From: "Sami Mohammed" <SMOHAMME..ndependenthealth.com>
    > >Reply-To: cayenne-use..bjectstyle.org
    > >To: <cayenne-use..bjectstyle.org>
    > >Subject: RE: Pagination query
    > >Date: Thu, 10 Feb 2005 14:39:47 -0500
    > >
    > >Hi Spoor,
    > >
    > >Thank you.
    > >How can i display the result on jsp page , if you any code that will be
    > >help ful for me.
    > >
    > >Thanks in advance.
    > >
    > >sami
    > >
    > > >>> lspoor_cayenn..otmail.com 02/10/05 02:25PM >>>
    > >Hi Sami,
    > >
    > >Just subclass the bean I have have attached: provided for example:
    > >
    > >public class ComplexList extends PagedObjectList
    > >{
    > > /**
    > > * Construstor
    > > *
    > > *..aram pList The list that is returned from a Cayenne Query
    > > *..aram pPageSize The length of the page
    > > *..aram pCurrentRow The current Row
    > > */
    > > public ComplexList ( List pList
    > > , int pPageSize
    > > , int pCurrentRow)
    > > {
    > > super(pList, pPageSize, pCurrentRow);
    > > } //ComplexList()
    > >
    > > /**
    > > * Constructor for unpaged list
    > > *..aram pList
    > > */
    > > public ComplexList (List pList)
    > > {
    > > super(pList, pList.size(), 0);
    > > } //ComplexList
    > >
    > >
    > >Usage:
    > >
    > > List lst = mContext.performQuery(qry);
    > >
    > > ComplexList cpxList = new ComplexList (lst, pPageSize,
    >pCurrentRow);
    > > cpxList.getSubSetList();
    > >
    > >--> cpxList.getSubsetList() returns the record set. If you choose to
    > >instantiate the bean like:
    > >
    > >ComplexList cpxList = new ComplexList(lst);
    > >
    > >Then cpxList.getSubsetList() returns everything.
    > >
    > >Hope this helps, Laszlo
    > >
    > >
    > >
    > > >From: "Sami Mohammed" <SMOHAMME..ndependenthealth.com>
    > > >Reply-To: cayenne-use..bjectstyle.org
    > > >To:
    ><cayenne-use..bjectstyle.org>,<cayenne-user-return-@objectstyle.org>
    > > >Subject: Pagination query
    > > >Date: Thu, 10 Feb 2005 14:02:07 -0500
    > > >
    > > >
    > > >Hi
    > > > >
    > > > > Thanks once again for your help.
    > > > > I have one proble that i have to do paginate in my
    > > > > webapplication. i have 2000 rows and i have to show 20
    > > > > rows on each page. could you send me the detail
    > > > > example of paginate with classes and jsp pages.
    > > > > i have your example below but that is not sufficant
    > > > > for me
    > > > >
    > > > > your tutorial example below:
    > > > > ---------------------
    > > > > import java.util.List;
    > > > > import java.util.Map;
    > > > > import org.objectstyle.cayenne.access.DataContext;
    > > > > import org.objectstyle.cayenne.query.SelectQuery;
    > > > > import org.objectstyle.art.Artist;
    > > > > ...
    > > > > DataContext ctxt;
    > > > >
    > > > > // create a query returning data rows
    > > > > SelectQuery q = new SelectQuery(Artist.class);
    > > > > q.setPageSize(50);
    > > > >
    > > > > // the fact that result is paged is transparent
    > > > > List artistRows = ctxt.performQuery(q);
    > > > >
    > > > >
    > > > > // we are reading from the first page (index < 50),
    > > > > // this will simply return an object
    > > > > Artist artist1 = (Artist)artistRows.get(3);
    > > > >
    > > > > // we are reading from the 4th page,
    > > > > // this will transparently resolve all objects on
    > > > > "Page #4"
    > > > > // and then return an object in question
    > > > > Artist artist2 = (Artist)artistRows.get(153);
    > > > >
    > > > >
    > > > > // This is safe and will NOT trigger a full fetch
    > > > > int size = artistRows.size();
    > > > > ...
    > > > > --------------------
    > > > > send me the jsp page where i can display 20 rows and
    > > > > next and previous page.
    > > >i need some sample example
    > > >
    > > > >
    > > > > thanks
    > > > > sami
    > > >
    > > >
    > >
    > >_________________________________________________________________
    > >Play online games with your friends with MSN Messenger
    > >http://messenger.msn.nl/
    > >
    >
    >_________________________________________________________________
    >MSN Search, for accurate results! http://search.msn.nl
    >

    _________________________________________________________________
    Talk with your online friends with MSN Messenger http://messenger.msn.nl/



    This archive was generated by hypermail 2.0.0 : Thu Feb 10 2005 - 15:52:06 EST