Following on from my previous post, I've managed to get it mostly working, so I
thought I'd include some code for people to check out.
Still haven't got the "displaying x to y" bit working, but I simply changed the
paging.banner.some_items_found property in displaytag.properties to:
paging.banner.some_items_found=<div class="bigborder"><table width="100%"
border="0" cellspacing="0" cellpadding="0"><tr class="tableRowAction"><td
align="left" valign="bottom" class="tableCellAction">{0} {1} found.</td>
and I guess I'll figure it out with a bit more digging. Any hints here would be
greatly appreciated.
I'm still having trouble with the last few pages not having data, so I'm
beginning to think that my calculation of "pageNumber * PAGE_SIZE" is a bit
naive... but what's the alternative?
Here's my struts Action execute method:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
Exception {
String forward = WebConstants.SUCCESS;
String sortColumn = getSortColumn(request, TABLE_ID);
String sortOrder = getSortOrder(request, TABLE_ID);
int pageNumber = getPageNumber(request, TABLE_ID);
int firstRecord = pageNumber * PAGE_SIZE;
String exporting = getExporting(request, TABLE_ID);
String exportType = getExportType(request, TABLE_ID);
request.setAttribute("resultSize", mappingsManager.countBudgets());
if (StringUtils.isBlank(exportType)) {
// Just get the items on the current page.
if (request.getAttribute(BUDGETS_ATTRIBUTE) == null) {
request.setAttribute(BUDGETS_ATTRIBUTE,
mappingsManager.getBudgets(firstRecord, PAGE_SIZE,
sortColumn));
}
} else {
// We are exporting to Excel, so get All the Budgets.
request.setAttribute(BUDGETS_ATTRIBUTE,
mappingsManager.getBudgets());
}
return mapping.findForward(forward);
}
My struts Action inherits from a class I called PagedAction:
public class PagedAction extends ActionSupport {
protected String getSortColumn(HttpServletRequest aRequest, String
aTableId) {
return aRequest.getParameter(new
ParamEncoder(aTableId).encodeParameterName(
TableTagParameters.PARAMETER_SORT));
}
protected String getSortOrder(HttpServletRequest aRequest, String aTableId)
{
return aRequest.getParameter(new
ParamEncoder(aTableId).encodeParameterName(
TableTagParameters.PARAMETER_ORDER));
}
protected int getPageNumber(HttpServletRequest aRequest, String aTableId) {
String pageNumberString = aRequest.getParameter(
new ParamEncoder(aTableId).encodeParameterName(
TableTagParameters.PARAMETER_PAGE));
int pageNumber = 0;
if (!StringUtils.isBlank(pageNumberString)) {
try {
pageNumber = (Integer.parseInt(pageNumberString));
} catch (NumberFormatException e) {
// Do nothing... assume startRecord is 0;
}
}
return pageNumber;
}
protected String getExporting(HttpServletRequest aRequest, String aTableId)
{
return aRequest.getParameter(new
ParamEncoder(aTableId).encodeParameterName(
TableTagParameters.PARAMETER_EXPORTING));
}
protected String getExportType(HttpServletRequest aRequest, String
aTableId) {
return aRequest.getParameter(new
ParamEncoder(aTableId).encodeParameterName(
TableTagParameters.PARAMETER_EXPORTTYPE));
}
}
This is a convenience class that all the Actions need to page through
externally sorted and paged data can subclass, and use these methods to find
the parameters for what page we are on and whether we are exporting to excel
etc.
I needed to check for excel export because even though the datasets can be
enormous sometimes (25K+ rows) the end users still needed to open the whole lot
in Excel. Yes, it's slow... but hey...
And here is the table on my JSP page:
<display:table name="advBuds" class="table" defaultsort="1"
export="true" pagesize="50" sort="external"
sort="external" defaultsort="3"
partialList="true" size="resultSize"
uid="adviserBudgets"
requestURI="/mappings/adviserBudget.do">
<display:setProperty name="export.excel.filename"
value="adviser_budget.xls" />
<display:setProperty name="export.excel" value="true" />
<display:setProperty name="export.xml" value="false" />
<display:setProperty name="export.csv" value="false" />
<display:column class="tagstyle" property="adviserGroup"
sortable="true" sortName="adviserGroup"
title="Adviser Group"/>
<display:column class="tagstyle"
property="employee.employeeNumber"
title="Employee Number"/>
<display:column class="tagstyle"
property="employeeFullName"
sortable="true"
sortName="employeeFullName" title="Adviser Name"/>
<display:column class="tagstyle" property="state"
sortable="true" sortName="state"
title="State"/>
<display:column class="tagstyle" property="revenueType"
sortable="true" sortName="revenueType"
title="Revenue Type"/>
<display:column class="tagstyle" property="month"
sortable="true" sortName="month"
title="Month"/>
<display:column class="tagstyle" property="year"
media="html"
sortable="true" sortName="year"
title="Year"/>
<display:column class="tagstyle" property="year"
media="excel"
sortable="true" title="Year"/>
<display:column class="tagstyle" property="budget"
media="html"
sortable="true" sortName="budget"
title="Budget"
style="text-align: right"
decorator="com.mbl.amr.table.PriceColumnDecorator"/>
<display:column class="tagstyle" property="budget"
media="excel"
sortable="true" sortName="budget"
title="Budget"/>
</display:table>
The "budget" column is in their twice, because the ColumnDecorator that I
causes the data to become unreadable when importing it into Excel... so one
column is for excel export without the decorator.
I'm using Hibernate Criteria searches at the DAO level, so the "sortName"
values are exactly the names of properties that can be fed into the
criteria.addOrder() method. Works pretty nicely.
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of David
Parry
Sent: Wednesday, 3 May 2006 5:31 PM
To: [email protected]
Subject: [displaytag-user] Examples of external sorting and paging
Is there any example code of external sorting and paging?
I'm working on some at the moment, but finding the documentation a little
thin...
Initial problems are:
1. How to get the toolbar to show the correct row numbers... currently I'm
always getting stuff like this:
25,344 items found, displaying 1 to 50. [ First/ Prev] 13, 14, 15, 16, 17, 18,
19, 20 [ Next / Last ]
It always seems to say "displaying 1 to 50".
What do I have to do to get that working correctly? Are there request
attributes I should set (like when I do size="resultSize")?
2. Pages seem to get out of sync towards the end of the list. I find that the
last 2 or 3 pages all say "0 items". Why would that be? It only happens
sometimes.
3. Exporting the whole thing to Excel... I only just found this out, and it's
gonna cause me some grief, I think. I want the end user to be able to page
through the large datasets (25K + rows), but then to be able to download the
WHOLE thing. With external paging on, I only get to download the current page.
I'm guessing that my workaround is going to be to take them to a "slow" page
that just loads the works, with the excel option turned on.
NOTICE
This e-mail and any attachments are confidential and may contain copyright
material of Macquarie Bank or third parties. If you are not the intended
recipient of this email you should not read, print, re-transmit, store or act
in reliance on this e-mail or any attachments, and should destroy all copies of
them. Macquarie Bank does not guarantee the integrity of any emails or any
attached files. The views or opinions expressed are the author's own and may
not reflect the views or opinions of Macquarie Bank.
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=k&kid0709&bid&3057&dat1642
_______________________________________________
displaytag-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/displaytag-user
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
displaytag-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/displaytag-user