数据的分页显示是web应用开发中的常规任务,它包括3项内容:数据分页,页码栏和生成表格。使用displaytag可以减少我们的重复劳动,提高我们的开发效率。
displaytag可以为我们完成的工作有:1)数据分页,这是数据在数据库外的分页。2)生成页码栏。3)将数据格式化成表格。
displaytag提供的功能覆盖了我们在开发数据分页显示时的全部内容。这些功能你可以让displaytag全部为你完成,也可以让tag为你完成部分,其余由你自己完成。
如果你想让displaytag为你完成全部工作。只要设定pagesize这个参数,告诉它每页显示的记录数就可以了。但是,这里你必须把所有的数据都传给tag。所以在数据库查询的性能上不能达到最优化。
<
display:table
id
="viewtotalcost"
export
="true"
name
="page.list"
pagesize
="page.count"
class
="its"
requestURI
="/cost/costTotalQueryByTypeAction.do"
>
< display:column property ="sectionName" title ="部门" />
< display:column property ="typeItemName" title ="费用类型" />
< display:column property ="remainMoney" title ="剩余额度" sortable ="true" style ="text-align:right" />
< display:column property ="limitedMoney" title ="费用额度" sortable ="true" style ="text-align:right" />
< display:column property ="occupaiedRatio" title ="占用比例" style ="text-align:right" />
< display:column property ="usedMoney" title ="已用额度" style ="text-align:right" />
< display:column property ="ratio" title ="已用比例" style ="text-align:right" />
< display:setProperty name ="export.csv" value ="false" />
< display:setProperty name ="export.excel.label" value ="下载Excle文件" />
</ display:table >
< display:column property ="sectionName" title ="部门" />
< display:column property ="typeItemName" title ="费用类型" />
< display:column property ="remainMoney" title ="剩余额度" sortable ="true" style ="text-align:right" />
< display:column property ="limitedMoney" title ="费用额度" sortable ="true" style ="text-align:right" />
< display:column property ="occupaiedRatio" title ="占用比例" style ="text-align:right" />
< display:column property ="usedMoney" title ="已用额度" style ="text-align:right" />
< display:column property ="ratio" title ="已用比例" style ="text-align:right" />
< display:setProperty name ="export.csv" value ="false" />
< display:setProperty name ="export.excel.label" value ="下载Excle文件" />
</ display:table >
如果,你想让tag为你完成工作2,和3。而数据分页的工作由你自己通过数据库分页查询来完成的话,也是可以的。这是你需要设置的参数有:partialList,size和pagesize。这时,displaytag只负责显示表格和页码栏,你也必须自己编码保证传给它的数据是已经经过分页的。
<
display:table
id
="log"
name
="logPage.list"
class
="its"
size
="logPage.count"
partialList
="true"
pagesize
="logPage.pageSize"
requestURI
="/log/logQueryAction.do"
>
< display:column property ="user.trueName" title ="操作者" />
< display:column property ="operateTime" title ="操作时间" />
< display:column property ="module.name" title ="模块" />
< display:column title ="菜单" >< c:out value ="${log.menu}" /> < c:out value ="${log.subMenu}" /></ display:column >
< display:column property ="action.name" title ="操作动作" />
</ display:table >
< display:column property ="user.trueName" title ="操作者" />
< display:column property ="operateTime" title ="操作时间" />
< display:column property ="module.name" title ="模块" />
< display:column title ="菜单" >< c:out value ="${log.menu}" /> < c:out value ="${log.subMenu}" /></ display:column >
< display:column property ="action.name" title ="操作动作" />
</ display:table >
最后,如果你只想使用displaytag的表格显示功能,连页码栏和数据分页都自己完成的话,也是可以的。这时,你pagesize,partialList和size这些参数一个都不要填.但是这时你就要自己编写页码栏的代码了.所以jsp就会比较长.
<
display:table
id
="viewcost"
name
="CostPage.list"
class
="its"
requestURI
="/cost/costQueryAction.do"
>
< display:column title ='' >
< c:if test ="${viewcost.confirmedFlg == '是'}" >
< input type ="checkbox" name ="check" value ="<c:out value='${viewcost.costId}'/>" disabled ="true" >
</ c:if >
< c:if test ="${viewcost.confirmedFlg == '否'}" >
< input type ="checkbox" name ="check" value ="<c:out value='${viewcost.costId}'/>" >
</ c:if ></ display:column >
< display:column property ="n" title ="序号" sortable ="true" />
< display:column property ="dateString" title ="申请日期" sortable ="true" />
< display:column title ="费用单号" sortable ="true" >< a href ="<c:url value='/cost/costAdminAction.do'><c:param name='method' value='read'/><c:param name='id' value='${viewcost.costId}'/></c:url>" >< c:out value ="${viewcost.costId}" /></ a ></ display:column >
< display:column property ="userId" title ="申请人" sortable ="true" />
< display:column property ="typeItemValue" title ="费用类型" />
< display:column title ="申请费用" sortable ="true" >
< div align ="right" >< font color ="#000000" >< c:out value ="${viewcost.fareString}" /></ font ></ div >
</ display:column >
< display:column property ="confirmedFlg" title ="是否复核" sortable ="true" />
< display:column title ="打印" sortable ="true" >< center >< a href ="javascript:OpenDialog('<c:url value='/cost/costAdminAction.do'><c:param name='method' value='print'/><c:param name='id' value='${viewcost.costId}'/></c:url>',650,770)" >< img src ="../images/boutonprint2.gif" border ="0" ></ a ></ display:column >
</ display:table >
< table width ="100%" >
< tr >
< td >< p align ="right" >
< a href ="<c:url value='/cost/costQueryAction.do'><c:param name='page' value='${CostPage.firstPage}'/><c:param name='confirmedFlg' value='${costQueryForm.confirmedFlg}'/></c:url>" > 第一 </ a >
< c:if test ="${CostPage.previous}" >
< a href ="<c:url value='/cost/costQueryAction.do'>
<c:param name='page' value='${CostPage.previousPage}'/>
<c:param name='confirmedFlg' value='${costQueryForm.confirmedFlg}'/>
</c:url>" > 上一 </ a >
</ c:if >
< c:if test ="${CostPage.next}" >
< a href ="<c:url value='/cost/costQueryAction.do'>
<c:param name='page' value='${CostPage.nextPage}'/>
<c:param name='confirmedFlg' value='${costQueryForm.confirmedFlg}'/>
</c:url>" > 下一 </ a >
</ c:if >
< a href ="<c:url value='/cost/costQueryAction.do'>
<c:param name='page' value='${CostPage.lastPage}'/>
<c:param name='confirmedFlg' value='${costQueryForm.confirmedFlg}'/>
</c:url>" > 最后一页 </ a > 查看:
< select onChange ="doRedirectSelectPage(this)" >
< c:forEach var ="index" begin ="${CostPage.firstPage}" end ="${CostPage.lastPage}" >
< c:if test ="${index == CostPage.page}" >
< option selected value ="<c:url value='/cost/costQueryAction.do'><c:param name='page' value='${index}'/> <c:param name='confirmedFlg' value='${costQueryForm.confirmedFlg}'/></c:url>" >< c:out value ="${index+1}" /></ option >
</ c:if >
< c:if test ="${index != CostPage.page}" >
< option value ="<c:url value='/cost/costQueryAction.do'><c:param name='page' value='${index}'/> <c:param name='confirmedFlg' value='${costQueryForm.confirmedFlg}'/></c:url>" >< c:out value ="${index+1}" /></ option >
</ c:if >
</ c:forEach ></ select ></ td >
</ tr >
</ table >
< display:column title ='' >
< c:if test ="${viewcost.confirmedFlg == '是'}" >
< input type ="checkbox" name ="check" value ="<c:out value='${viewcost.costId}'/>" disabled ="true" >
</ c:if >
< c:if test ="${viewcost.confirmedFlg == '否'}" >
< input type ="checkbox" name ="check" value ="<c:out value='${viewcost.costId}'/>" >
</ c:if ></ display:column >
< display:column property ="n" title ="序号" sortable ="true" />
< display:column property ="dateString" title ="申请日期" sortable ="true" />
< display:column title ="费用单号" sortable ="true" >< a href ="<c:url value='/cost/costAdminAction.do'><c:param name='method' value='read'/><c:param name='id' value='${viewcost.costId}'/></c:url>" >< c:out value ="${viewcost.costId}" /></ a ></ display:column >
< display:column property ="userId" title ="申请人" sortable ="true" />
< display:column property ="typeItemValue" title ="费用类型" />
< display:column title ="申请费用" sortable ="true" >
< div align ="right" >< font color ="#000000" >< c:out value ="${viewcost.fareString}" /></ font ></ div >
</ display:column >
< display:column property ="confirmedFlg" title ="是否复核" sortable ="true" />
< display:column title ="打印" sortable ="true" >< center >< a href ="javascript:OpenDialog('<c:url value='/cost/costAdminAction.do'><c:param name='method' value='print'/><c:param name='id' value='${viewcost.costId}'/></c:url>',650,770)" >< img src ="../images/boutonprint2.gif" border ="0" ></ a ></ display:column >
</ display:table >
< table width ="100%" >
< tr >
< td >< p align ="right" >
< a href ="<c:url value='/cost/costQueryAction.do'><c:param name='page' value='${CostPage.firstPage}'/><c:param name='confirmedFlg' value='${costQueryForm.confirmedFlg}'/></c:url>" > 第一 </ a >
< c:if test ="${CostPage.previous}" >
< a href ="<c:url value='/cost/costQueryAction.do'>
<c:param name='page' value='${CostPage.previousPage}'/>
<c:param name='confirmedFlg' value='${costQueryForm.confirmedFlg}'/>
</c:url>" > 上一 </ a >
</ c:if >
< c:if test ="${CostPage.next}" >
< a href ="<c:url value='/cost/costQueryAction.do'>
<c:param name='page' value='${CostPage.nextPage}'/>
<c:param name='confirmedFlg' value='${costQueryForm.confirmedFlg}'/>
</c:url>" > 下一 </ a >
</ c:if >
< a href ="<c:url value='/cost/costQueryAction.do'>
<c:param name='page' value='${CostPage.lastPage}'/>
<c:param name='confirmedFlg' value='${costQueryForm.confirmedFlg}'/>
</c:url>" > 最后一页 </ a > 查看:
< select onChange ="doRedirectSelectPage(this)" >
< c:forEach var ="index" begin ="${CostPage.firstPage}" end ="${CostPage.lastPage}" >
< c:if test ="${index == CostPage.page}" >
< option selected value ="<c:url value='/cost/costQueryAction.do'><c:param name='page' value='${index}'/> <c:param name='confirmedFlg' value='${costQueryForm.confirmedFlg}'/></c:url>" >< c:out value ="${index+1}" /></ option >
</ c:if >
< c:if test ="${index != CostPage.page}" >
< option value ="<c:url value='/cost/costQueryAction.do'><c:param name='page' value='${index}'/> <c:param name='confirmedFlg' value='${costQueryForm.confirmedFlg}'/></c:url>" >< c:out value ="${index+1}" /></ option >
</ c:if >
</ c:forEach ></ select ></ td >
</ tr >
</ table >