You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Hugh Brien <hu...@novuscg.com> on 2001/11/02 20:02:15 UTC

Pagination in Portlets

Does anyone have a suggestion for doing pagination with Velocity
templates.  For example I have 200 items and I want to display them 20
at a time
r,
Hugh

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Pagination in Portlets

Posted by Dan Bachelder <ch...@chowda.net>.
Another way that may be better or worse depending on what you are doing:

get a list of all the primary keys

(maybe cache the list)

and use criteria.addIn(chunkOList) to get the actual page of rows when you
need them.

this method is good for places where data staleness is not a big problem (if
you cache) and where paging is apt to be done often.. you'll need to use
sort criteria in both places though.. so if you need sorting the first query
cant be JUST for the key...



----- Original Message -----
From: "Daniel Rall" <dl...@finemaltcoding.com>
To: "Turbine Users List" <tu...@jakarta.apache.org>
Sent: Friday, November 02, 2001 3:37 PM
Subject: Re: Pagination in Portlets


> "Hugh Brien" <hu...@novuscg.com> writes:
>
> > Does anyone have a suggestion for doing pagination with Velocity
> > templates.  For example I have 200 items and I want to display them 20
> > at a time
>
> o Determine how many items you want to display per page (I call this a
> window)
>
> o Determine how many total items you have
>
> o Get only the items that you want (with an RDBMS, this usually
> requires that you get all the items up to the end of your window),
> determined by a window start parameter
>
> o Iterate items in your window and show to user
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Pagination in Portlets

Posted by Daniel Rall <dl...@finemaltcoding.com>.
"Davis Kulis" <da...@datapro.lv> writes:

>> o Get only the items that you want (with an RDBMS, this usually
>> requires that you get all the items up to the end of your window),
>> determined by a window start parameter
>
> Well, if you know the last item of previous window and your data is sorted
> on some column(s), you can avoid that.
>
> Say you have table T with cols ID (primary key) and A, output beeing sorted
> by A (and then by ID to add determinism). Last item on previous window has
> ID=10 and A="value".
>
> Now use statement
> "select ID, A from T where
>     (A > "value") or
>     (A = "value" and ID > 10)
> order by A asc, ID asc
>
> So now first row you get is first to be shown. I'm sure this can easily be
> translated into criteria, but I haven't  tried it myself.

Thanks Davis, using the sort criteria is a good optimization.

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Pagination in Portlets

Posted by Davis Kulis <da...@datapro.lv>.
> > Does anyone have a suggestion for doing pagination with Velocity
> > templates.  For example I have 200 items and I want to
> > display them 20 at a time
>
> o Determine how many items you want to display per page (I call this a
> window)
>
> o Determine how many total items you have
>
> o Get only the items that you want (with an RDBMS, this usually
> requires that you get all the items up to the end of your window),
> determined by a window start parameter

Well, if you know the last item of previous window and your data is sorted
on some column(s), you can avoid that.

Say you have table T with cols ID (primary key) and A, output beeing sorted
by A (and then by ID to add determinism). Last item on previous window has
ID=10 and A="value".

Now use statement
"select ID, A from T where
    (A > "value") or
    (A = "value" and ID > 10)
order by A asc, ID asc

So now first row you get is first to be shown. I'm sure this can easily be
translated into criteria, but I haven't  tried it myself.

> o Iterate items in your window and show to user

rgrds
Davis


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Pagination in Portlets

Posted by Daniel Rall <dl...@finemaltcoding.com>.
"Hugh Brien" <hu...@novuscg.com> writes:

> Does anyone have a suggestion for doing pagination with Velocity
> templates.  For example I have 200 items and I want to display them 20
> at a time

o Determine how many items you want to display per page (I call this a
window)

o Determine how many total items you have

o Get only the items that you want (with an RDBMS, this usually
requires that you get all the items up to the end of your window),
determined by a window start parameter

o Iterate items in your window and show to user

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>