时光如水

我心跳动
posts - 6, comments - 10, trackbacks - 0, articles - 4
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

displayTag学习摘要

Posted on 2005-11-21 17:11 qiqijava 阅读(754) 评论(1)  编辑  收藏 所属分类: Tag

当时想要这样一个标签,能实现分页、排序、过滤、搜索功能,且页面比较美观。先后学习了三个比较有名的标签:displayTag、eXtremeComponents、valueList。个人感觉:

display上手容易,功能简单,界面漂亮,不过功能比较有限。感觉最不爽的就是在一页上排好序后,再点击下一页后,排序就乱了。而且当数据量大时,它的排序会有问题

eXtremeComponents上手容易,操作烦索,界面一般,不过起码在排序上就没有displayTag的问题。数据量大时,它的排序也会有问题

valueList我认为最强大的标签,需要与spring结合使用,上手不易,界面漂亮,功能超强。目前没有发现任何不爽的地方。

先贴出display的心得,后续会贴出其它两个的心得


                                  displayTag学习摘要
1.tableTag中name属性:值默认作用域:request
<display:table name="accList">
如果作用域为session,则<display:table name="sessionScope.accList">
tableTag中指定ID属性会把该对象加入到pageContext对象中去。如ID="test"
<%int cate=((Role)pageContext.getAttribute("test")).getCategory();%>
生成表格的序列号 例如:<display:table id="row" name="mylist">
<display:column title="序列号"><%=pageContext.getAttribute("row_rowNum")%></display:column>
如行号:row_rowNum <c:out value="${row_rowNum}"/>
firstName:row.firstName   <c:out value="${row.firstName}"/>
lastName: row.lastName  全部由ID来取得

2.限制页面显示的结果集数
 1)全部<display:table name="accList" class="its" id="test">
 2)头5个<display:table name="accList" class="its" id="test" length="5">
 3)从第二个开始,显示下5个<display:table name="accList" class="its" id="test" offset="2" length="5">

3.包装器decorators,有行包装器(必须继承TableDecorator)和列包装器(必须实现ColumnDecorator)
  在tableTag中显示list时,decorators中的方法会在list前调用,如果decorators实现类中有相关的getXXX()方法时,调用此方法,如果没有,则直接调用list
  在columnTag中显示value时,decorators中的方法会先调用,(应该重用)

4.传递参数,有两种方式,
  一。struts方式:有以下几个属性
  1)href 基本的超连接
  2)paramId 添加到url上的参数名
  <display:column property="status" href="details.jsp" paramId="id" paramProperty="id" />
  3)paramName 传递容器内的其它bean当作参数 如:request.setAttribute("testparam", "sendamail");
  <display:column property="email" href="details.jsp" paramId="action" paramName="testparam" paramScope="request" />
  4)paramScope 指定bean的作用域
  二。decorators方式
  类Wrapper方法:public String getLink1()
 {
  ListObject lObject= (ListObject)getCurrentRowObject();
  int lIndex= getListIndex();
  return "<a href="details.jsp?index=" + lIndex + "">" + lObject.getId() + "</a>";
 }标签:
 <display:table name="sessionScope.details" decorator="org.displaytag.sample.Wrapper" >
  <display:column property="link1" title="ID" />
  <display:column property="email" />
</display:table>

5.分页
  指定属性:pagesize="10" 每页显示10条记录

6.排序
  1)在list中封装的对象的属性要实现Comparable接口,(一般均实现了)
  2) 在columnTag中指定sortable="true"
  可指定默认排序的列 defaultsort="1" 数值为第几列默认排序 defaultorder="descending" 指定默认为降序

7.导出 支持下列格式:'html', 'xml', 'csv', and 'excel'.
  属性:export="true",注意导出无效,当使用jsp:include or the RequestDispatcher
  <display:column media="csv excel" title="URL" property="url"/>
  指定该url属性值只能在csv、excel中导出
  需要指定export filter.

8.更改默认设置
  1)通过<display:setProperty name=... value=...> 标签,可以覆盖一些默认设置
  2)创建displaytag.properties文件,所有时区共用,建中文编码则创建displaytag_zh_cn.properties,放到类路径下,jar包内共有两个默认的属性文件TableTag.properties,message.properties

9其它
  1)当多个表在一页显示时,每个表都想要有分页、排序、导出等功能时,只需为每个table指定一个不同的ID即可。
  2)增加表头<display:caption>角色管理</display:caption>
  3)增加表尾  <display:footer><tr><td colspan="6" align="center" >国瑞数码版权所有</td></tr></display:footer>
  4)http和email自动链接功能,指定autolink="true"
  5)指定一列显示的最大长度,避免太长把表格变形 maxLength="10" style="whitespace: nowrap;"
  6)当列的值为null,使用nulls="false"属性把null转为空白


评论

# re: displayTag学习摘要  回复  更多评论   

2009-06-30 22:40 by 孤寂
还是不太懂也

只有注册用户登录后才能发表评论。


网站导航: