Hugh-
I have a colleague who has just coded some pagination stuff, here is his
response to your mail...
-B
--
===========================
Brian Lawler
---------- Forwarded message ----------
Date: Fri, 02 Nov 2001 14:29:57 -0800
From: Corey Krehel <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: Re: Pagination in Portlets (fwd)
Hugh-
I recently had to impliment pagination on our site as well, and had to do it
in the following way:
The following code uses velocity entirely to paginate a list of items.
I should note, however, that I was forced to do it this way because the
context object that I was looping through was an Array not and ArrayList. An
ArrayList would have made this easier to do as I could have looped through
the arraylist and made smaller arrays based on the number of items to show
per page (ie, 10 arrays of 20 items for 200 total items). I dont know what
you are going to be handling in the template, but If it is an arraylist, you
should check look into the methods and properties of that util.
My script is attached, but, I should say that, given alternatives, its
pretty hacky. But if you are stuck using only velcoity to do this, it works
really well. Lastly, I expanded on this pagination to include drop down to
display of all the ranges (1-10, 11-20, 21-30 etc). I also created a drop
down which allows users to choose the # of items to show per page (10, 20,
30, etc). It works pretty well with a little JS included. Let me know if
you want some info on that, but I think this script give enough info to
figure out the rest.
Peace
Corey
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
## In a macro for creating a list
## FIRST:
## 1. $list is the array/arraylist etc. $template is the target template for
the links we'll build.
## 2. set all the pagination params, check to see if there is a NOT a
pagination var(pv) in the url.
## 3. otherwise set the starting position = to the value of pv
## 4. now set the ending position equal to the starting position + x(in your
example 19)
#macro(paginatedList $list $template)
#if(!$data.parameters.pv)
#set($setPagn8 = 1)
#else
#set($setPagn8 = $data.getParameters().getInt("pv"))
#end
#set($endPagn8 = $setPagn8 + 19)
## SECOND:
## I should note here that I will be using Velocity's $velocityCount
function which is, in my app, configured to start counting at 1, not 0, this
is configurable and you should check it as it will change the values you
calculate.
## 1. now we start looping through our array
## 2. create a current position value ($currpos) and use $velocityCount to
set the value
## 3. now use $currPos test to see if the current item is in our range
(1-20)
## 4. if the item is not in the range. create a var called #nextPagn8 that
well use in a link. the value is the last # in our range + 1.
#foreach ($item in $list)
#set ($currPos = $velocityCount)
#if ($currPos >= $setPagn8 && $curPos <= $endPagn8)
$item.itemPropery
#else
#set($nextPagn8 = $endPagn8 +1)
#end
#end
## THIRD
## ok now we make our links at the bottom of the list.
## 1. get the total number of items. The loop is finished and curPos is now
set to our last item. With an array list you can use. items.size()
## 2. See if our end value is larger than our delimeter (20) if it is,
create a previous link.
## 3. set a prev value which is the setvalue for this section of the list
minus our delimeter.
## 4. add that to the url
## 5. Now test to see if our page count is bigger than our the last item we
displayed in our list. If it is create a link that looks like this 1-20 (of
x)
## 6. Last if the total # of items is bigger larger than our last displayed
item, create a next link.
#set($pageCount = $currPos)
#if($endPagn8 > 20)
#set($prevPagn8 = $setPagn8 - 20)
<a
href="yourlinkinfo.setPage$template).addQueryData"pv",$prevPagn8)">Prev</a>
#end
#if($pageCount >= $endPagn8)
#set($menuEndPagn8 = $endPagn8)
#elseif($pageCount < $endPagn8)
#set($menuEndPagn8 = $pageCount)
#end
$setPagn8 - $menuEndPagn8 (of $pageCount)
#if($pageCount > $endPagn8)
<a href="yourlinkinfo.setPage($template).addQueryData("pv",
$nextPagn8)">Next</a>
#end
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>