Hi Angelo, I achieve custom paging for anything that uses a tapestry
loop (or anything that needs a list per page) starting with this
abstract class:
public abstract class PagingResults T
{
protected int _page;
protected int _resultsPerPage;
public PagingResults (int resultsPerPage)
{
_page = 1;
_resultsPerPage = resultsPerPage;
}
public ListT getCurrentPage () throws Exception
{
ListT pageOfResults = getResultsStartingAt( (_page - 1) *
_resultsPerPage, _resultsPerPage);
return pageOfResults;
}
public void incrementPage ()
{
if (_page lastPage()) _page++;
}
public void decrementPage ()
{
if (_page 1) _page--;
}
public void toLastPage ()
{
_page = lastPage();
}
public int lastPage ()
{
return
(int)Math.ceil((double)getTotalResults()/(double)_resultsPerPage);
}
public void reset ()
{
_page = 1;
}
public int getPage ()
{
return _page;
}
public int getResultsPerPage ()
{
return _resultsPerPage;
}
public abstract ListT getResultsStartingAt (int start, int
numToGet) throws Exception;
public abstract long getTotalResults ();
}
This class' getCurrentPage() method returns a sublist of the total
list for use in the loop, etc. Subclasses of this define the
getResultsStartingAt() and the total number of results. I usually
define subclasses of PagingResults as simple inner classes of my
page/component classes where the services I need are injected.
I have a companion component to this:
public class Pager
{
@Parameter (required = true)
private PagingResults _pagingResults;
@Inject
private Messages _messages;
@Inject
private ComponentResources _resources;
void onActionFromToFirst ()
{
_pagingResults.reset();
}
void onActionFromToPrevious ()
{
_pagingResults.decrementPage();
}
void onActionFromToNext ()
{
_pagingResults.incrementPage();
}
void onActionFromToLast ()
{
_pagingResults.toLastPage();
}
public String getPagerInfo ()
{
String s = ;
int startInd = (_pagingResults.getPage() - 1) *
_pagingResults.getResultsPerPage() + 1;
long endInd = (startInd + _pagingResults.getResultsPerPage() -
1 _pagingResults.getTotalResults()) ?
_pagingResults.getTotalResults() : startInd +
_pagingResults.getResultsPerPage() - 1;
s = startInd + - + endInd + + _messages.get(of) +
+ _pagingResults.getTotalResults();
return s;
}
public boolean getOnFirstPage ()
{
return _pagingResults.getPage() == 1;
}
public boolean getOnLastPage ()
{
return _pagingResults.getPage() == _pagingResults.lastPage();
}
}
The template for this Pager component is simple:
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;
div class=peoplepad_pager
xmlns:t=http://tapestry.apache.org/schema/tapestry_5_0_0.xsd;
${pagerInfo} nbsp; t:actionlink t:id=toFirst
disabled=onFirstPage${message:first}/t:actionlink
|
t:actionlink t:id=toPrevious disabled=onFirstPagelt;
${message:previous.abbrev}/t:actionlink
|
t:actionlink t:id=toNext disabled=onLastPage${message:next}
gt;/t:actionlink
|
t:actionlink t:id=toLast
disabled=onLastPage${message:last}/t:actionlink
/div
In the page/component that uses all this I have a loop (typically)
with source=pagingResults.currentPage. The around the list I place
the pager component which takes the same PagingResults object as a
parameter.
Note this is not setup for Ajax interaction, just standard action
links (Http gets).
Cheers,
Bill
On Sun, Aug 31, 2008 at 8:32 PM, Angelo Chen [EMAIL PROTECTED] wrote:
Hi,
I have a need to display some Hibernate resultset with pagination, but I
can't use T5's grid. any hint how to do this in T5? thanks.
Angelo
--
View this message in context:
http://www.nabble.com/t5%3A-Hibernate-resultset-with-pagination-tp19247842p19247842.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Bill @ PeoplePad
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]