假如作用域为session,则display:table name="sessionScope.accList"> tableTag中指定ID属性会把该对象加入到pageContext对象中去。如ID=" />
龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

Java高级编程之displayTag学习摘要

时间:2009-12-23 15:42来源:未知 作者:admin 点击:
分享到:
1.tableTag中name属性:值默认作用域:request display:table name="accList"> 假如作用域为session,则display:table name="sessionScope.accList"> tableTag中指定ID属性会把该对象加入到pageContext对象中去。如ID=

  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即可。
  
精彩图集

赞助商链接