在一篇blog里我在回復(fù)里寫了displaytag1.1大數(shù)據(jù)量分頁(yè)顯示的索引存在bug
http://www.tkk7.com/zJun/archive/2006/02/27/32723.html
后來(lái)下載源代碼下來(lái)找到了修改bug的地方。
并把代碼發(fā)到 displaytag的jira里了,具體地址在:
http://jira.codehaus.org/browse/DISPL-303 (有人已經(jīng)提交這個(gè)bug了)
org.displaytag.pagination.SmartListHelper.java
把下面兩個(gè)方法的代碼改寫如下:
public int getFirstIndexForCurrentPage() {
return (this.currentPage - 1) * this.pageSize;
}
/**
* Returns the index into the master list of the last object that should appear on the current page that the user is
* viewing.
* @return int
*/
protected int getLastIndexForCurrentPage() {
if (this.partialList) {
return (getFirstIndexForCurrentPage()) +
Math.min(this.pageSize - 1, this.fullList.size() - 1);
} else {
return getLastIndexForPage(this.currentPage);
}
}
順便記錄 displaytag 1.1 使用Partial Lists大數(shù)據(jù)量分頁(yè)的例子:
在近量不改動(dòng)現(xiàn)有代碼的基礎(chǔ)上來(lái)使用displaytag結(jié)合數(shù)據(jù)庫(kù)分頁(yè).
1.先設(shè)置總頁(yè)數(shù):
<%
Integer totalNum = new Integer(919);
request.setAttribute("totalNum",totalNum);//設(shè)置總記錄條數(shù)
%>
2.配置displaytag的 兩個(gè)屬性:partialList="true" size="totalNum"
比如:
<display:table id="testtbid" name="requestScope.testlist" pagesize="20" partialList="true" size="totalNum">
3.在jsp中獲得翻頁(yè)信息的代碼:
<%
下面代碼是取得翻頁(yè)數(shù)
//如果沒(méi)有為table設(shè)置 id那么就要寫成ParamEncoder(null);
String rpname = new org.displaytag.util.ParamEncoder("testtbid")
.encodeParameterName(
org.displaytag.tags.TableTagParameters.PARAMETER_PAGE);
System.out.println("當(dāng)前頁(yè)數(shù):" + rpname + " = " +
request.getParameter(rpname));
//然后根據(jù)當(dāng)前頁(yè)數(shù)去從數(shù)據(jù)庫(kù)中取出相應(yīng)數(shù)據(jù)。
//see: http://displaytag.sourceforge.net/11/displaytag/apidocs/org/displaytag/tags/TableTagParameters.html
%>
表格分頁(yè)導(dǎo)航條里的分頁(yè)鏈接個(gè)數(shù)默認(rèn)是8個(gè),可以通過(guò)下面的代碼來(lái)更改
//在<display:table>標(biāo)簽內(nèi)
<display:setProperty name="paging.banner.group_size" value="20"/>
//</display:table>
當(dāng)然也可以通過(guò)實(shí)現(xiàn) org.displaytag.pagination.PaginatedList接口來(lái)完成這個(gè)要求。
更多信息,請(qǐng)參考:
http://displaytag.sourceforge.net/11/tut_externalSortAndPage.html
利用內(nèi)置el在displaytag里顯示checkbox非常簡(jiǎn)單:
<display:column title='select User' >
<input type="checkbox" name="firstName" value="{testtbid.name}" />${testtbid.name}
</display:column>