Java高级编程之displayTag学习摘要

王朝java/jsp·作者佚名  2008-05-19
窄屏简体版  字體: |||超大  

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转为空白

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航