服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

java高级编程之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转为空白

扫描关注微信公众号