Blog系统开发 13. 小细节 (2) 分页问题displaytag Part(1)
随着博文的增加或者评论的增加,是必要考虑一下分页问题。
在这个项目里,对于分页问题,我采取2种处理的方法。对于管理页面表格型的记录采用displayTag组件;
而对于那些博文或者评论采用自己写的PageTags类来管理。
1. displayTag组件
将displaytag- version.jar 文件与以下5个文件一起放置在应用的WEB-INF/lib目录里
b. 使用:
这里使用blog列表做例子
对于每条记录我们可能有显示要求
是不是很简单。
c.其他问题:
配置文件displaytag.properties,需要放置在src目录的根部,主要显示一些文字之类的设置,支持localization,但是要注意的是,文件必须转换成unicode才可以正常显着。
以下是displaytag_Zh_CN.properties的示例:
在这个项目里,对于分页问题,我采取2种处理的方法。对于管理页面表格型的记录采用displayTag组件;
而对于那些博文或者评论采用自己写的PageTags类来管理。
1. displayTag组件
上面的图片可以看出:事实上这个display tag库就是用来显示表格的;给它一个对象的list,它将搞定类似显示列,排序,分页等等事务,并以表格的形式显示出来。
a. 安装:将displaytag- version.jar 文件与以下5个文件一起放置在应用的WEB-INF/lib目录里
- commons-logging
- commons-lang
- commons-collections
- commons-beanutils
- log4j
<%
@ taglib uri
=
"
http://displaytag.sf.net
"
prefix
=
"
display
"
%>
b. 使用:
这里使用blog列表做例子
<%
List blogs
=
(List) request.getAttribute(
"
blogs
"
);
%>
< h2 > 文章管理 </ h2 >
< display:table name ="blogs" htmlId ="tab" pagesize ="10" />
每页显示10条记录
< h2 > 文章管理 </ h2 >
< display:table name ="blogs" htmlId ="tab" pagesize ="10" />
对于每条记录我们可能有显示要求
<
display:table
name
="blogs"
id
=" blog"
htmlId
="tab"
pagesize
="10"
>
< display:column property ="id" title ="编号" />
< display:column property ="title" title ="主题" />
< display:column property ="category" title ="类别" />
< display:column property ="date" format ="{0,date,yyyy-MM-dd HH:mm:ss}" title ="日期" ,sortable="true"/>
< display:column title ="操作" >
< a href ="/Blogs/BlogServlet?method=edit&id=${blog.id}" >< img src ="/Blogs/admin/img/edit.gif" border =0 /></ a >
< a href ="/Blogs/BlogServlet?method=delete&id=${blog.id}" onclick ="javascript:return del()" >< img src ="/Blogs/admin/img/delete.gif" border =0 /></ a > |
< a href ="/Blogs/CommentServlet?method=list&bid=${blog.id}" > 管理评论 </ td >
</ display:column >
</ display:table >
比如id字段显示为 标号;title主题;category类别;日期么安装年-月-日 小时:分钟:秒的格式显示;并且可以手动选择排序。
< display:column property ="id" title ="编号" />
< display:column property ="title" title ="主题" />
< display:column property ="category" title ="类别" />
< display:column property ="date" format ="{0,date,yyyy-MM-dd HH:mm:ss}" title ="日期" ,sortable="true"/>
< display:column title ="操作" >
< a href ="/Blogs/BlogServlet?method=edit&id=${blog.id}" >< img src ="/Blogs/admin/img/edit.gif" border =0 /></ a >
< a href ="/Blogs/BlogServlet?method=delete&id=${blog.id}" onclick ="javascript:return del()" >< img src ="/Blogs/admin/img/delete.gif" border =0 /></ a > |
< a href ="/Blogs/CommentServlet?method=list&bid=${blog.id}" > 管理评论 </ td >
</ display:column >
</ display:table >
是不是很简单。
c.其他问题:
配置文件displaytag.properties,需要放置在src目录的根部,主要显示一些文字之类的设置,支持localization,但是要注意的是,文件必须转换成unicode才可以正常显着。
以下是displaytag_Zh_CN.properties的示例:
1
#sort.behavior
=
list
2 #sort.amount = list
3 #basic.empty.showtable = true
4 #basic.msg.empty_list = No results matched your criteria.
5 #paging.banner.placement = top
6 #paging.banner.onepage = <span class = " pagelinks " ></span>
7 export.types = csv excel xml pdf rtf
8 export.excel = true
9 export.csv = true
10 export.xml = true
11 export.pdf = true
12 export.rtf = true
13 export.excel.class = org.displaytag.export.excel.DefaultHssfExportView
14 export.pdf.class = org.displaytag.export.DefaultPdfExportView
15 export.rtf.class = org.displaytag.export.DefaultRtfExportView
16 # if set , file is downloaded instead of opened in the browser window
17 #export. [ mymedia ] .filename =
18 paging.banner.placement = bottom
19 # messages
20
21 basic.msg.empty_list = \u6CA1\u6709\u7B26\u5408\u6761\u4EF6\u7684\u8BB0\u5F55
22 basic.msg.empty_list_row = <tr class = " empty " ><td colspan = " {0} " >\u6CA1\u6709\u7B26\u5408\u6761\u4EF6\u7684\u8BB0\u5F55</td></tr>
23 error.msg.invalid_page = \u65E0\u6548\u9875\u9762
24
25 export.banner = <div class = " exportlinks " >Export options: { 0 }</div>
26 export.banner.sepchar = |
27
28 paging.banner.item_name =
29 paging.banner.items_name =
30
31 paging.banner.no_items_found =
32 paging.banner.one_item_found =
33 paging.banner.all_items_found =
34 paging.banner.some_items_found =
35
36 paging.banner.full = <span class = " pagelinks " ><font align> [ <a href="{1}">|<</a>/<a href="{2}"><</a> ] { 0 } [ <a href="{3}">></a>/<a href="{4}">>|</a> ] </span>
37 paging.banner.first = <span class = " pagelinks " > [ \u9996\u9875/\u4E0A\u4E00\u9875 ] { 0 } [ <a href="{3}">\u4E0B\u4E00\u9875</a>/<a href="{4}">\u5C3E\u9875</a> ] </span>
38 paging.banner.last = <span class = " pagelinks " > [ <a href="{1}">\u9996\u9875</a>/<a href="{2}">\u4E0A\u4E00\u9875</a> ] { 0 } [ \u4E0B\u4E00\u9875/\u5C3E\u9875 ] </span>
39 paging.banner.onepage = <span class = " pagelinks " >{ 0 }</span>
40
41 paging.banner.page.selected = <strong>{ 0 }</strong>
42 paging.banner.page.link = <a href = " {1} " title = " {0} " >{ 0 }</a>
43 paging.banner.page.separator =, \
38行
paging.banner.placement
=
bottom 指定分页栏出现在表格的下面,当然还有top/both两个选择。
2 #sort.amount = list
3 #basic.empty.showtable = true
4 #basic.msg.empty_list = No results matched your criteria.
5 #paging.banner.placement = top
6 #paging.banner.onepage = <span class = " pagelinks " ></span>
7 export.types = csv excel xml pdf rtf
8 export.excel = true
9 export.csv = true
10 export.xml = true
11 export.pdf = true
12 export.rtf = true
13 export.excel.class = org.displaytag.export.excel.DefaultHssfExportView
14 export.pdf.class = org.displaytag.export.DefaultPdfExportView
15 export.rtf.class = org.displaytag.export.DefaultRtfExportView
16 # if set , file is downloaded instead of opened in the browser window
17 #export. [ mymedia ] .filename =
18 paging.banner.placement = bottom
19 # messages
20
21 basic.msg.empty_list = \u6CA1\u6709\u7B26\u5408\u6761\u4EF6\u7684\u8BB0\u5F55
22 basic.msg.empty_list_row = <tr class = " empty " ><td colspan = " {0} " >\u6CA1\u6709\u7B26\u5408\u6761\u4EF6\u7684\u8BB0\u5F55</td></tr>
23 error.msg.invalid_page = \u65E0\u6548\u9875\u9762
24
25 export.banner = <div class = " exportlinks " >Export options: { 0 }</div>
26 export.banner.sepchar = |
27
28 paging.banner.item_name =
29 paging.banner.items_name =
30
31 paging.banner.no_items_found =
32 paging.banner.one_item_found =
33 paging.banner.all_items_found =
34 paging.banner.some_items_found =
35
36 paging.banner.full = <span class = " pagelinks " ><font align> [ <a href="{1}">|<</a>/<a href="{2}"><</a> ] { 0 } [ <a href="{3}">></a>/<a href="{4}">>|</a> ] </span>
37 paging.banner.first = <span class = " pagelinks " > [ \u9996\u9875/\u4E0A\u4E00\u9875 ] { 0 } [ <a href="{3}">\u4E0B\u4E00\u9875</a>/<a href="{4}">\u5C3E\u9875</a> ] </span>
38 paging.banner.last = <span class = " pagelinks " > [ <a href="{1}">\u9996\u9875</a>/<a href="{2}">\u4E0A\u4E00\u9875</a> ] { 0 } [ \u4E0B\u4E00\u9875/\u5C3E\u9875 ] </span>
39 paging.banner.onepage = <span class = " pagelinks " >{ 0 }</span>
40
41 paging.banner.page.selected = <strong>{ 0 }</strong>
42 paging.banner.page.link = <a href = " {1} " title = " {0} " >{ 0 }</a>
43 paging.banner.page.separator =, \