使用displaytag进行分页显示

要格式化显示数据,又写不好自己的分页程序。不如试试displaytag标签。displaytag即可以进行几十万条的数据同时加载进行分页又可以定制自己的样式。当然它还有许多其他的功能,因为使用时间不长。我也不太清楚.这里只讲它的分页功能就好了。

要用displaytag标签进行动态数据分页,在WEB工程的LIB里加入displaytag.jar。然后在JSP页面里加入这句代码就可以使用displaytag标签了。

<%@ taglib uri="http://displaytag.sf.net/el" prefix="display" %>

要分页显示肯定得有这么几步是少不了的

1.工具类或者分页类。2.准备数据。3.绑定数据的JSP

实现思路:可以自己写个包装类用于你要进行分页显示的BEAN。也就是上面提到的第一步类似一个工具类.源码如下:

import org.displaytag.decorator.TableDecorator;

public class Wrapper extends TableDecorator {

    public String getDeptId(){
     Demo organise = (Demo)getCurrentRowObject();
     String demoid = organise.getId();
     if(demoid==null){
      demoid="";
     }
        StringBuffer htmlStr = new StringBuffer();
        htmlStr.append("<div align='center'><a href='../organization/deptEdit.htm?parentId=");//在这里加//一句这样的代码可以对单条记录进行修改。
        htmlStr.append(organise.getId());
        htmlStr.append("'>");
        htmlStr.append(demoid);
        htmlStr.append("</a></div>");
        return htmlStr.toString();
    }

}

2.准备数据:

在ACTION里或者controller取得业务逻辑层传递过来的数据并绑定在request作用域里。

  HttpSession session = (HttpSession)request.getSession(true);
  String pageListSize = (String)session.getAttribute("PAGE_LIST_SIZE");
  String type = request.getParameter("operation");

  if (pageListSize == null) {
   session.setAttribute("PAGE_LIST_SIZE", "10");
   pageListSize = "10";
  }
  if(type.equals("zx")){
  List list = dataSource.getData();
  request.setAttribute("operation","zx");
  request.setAttribute("list",list);
  }
  if(type.equals("gd")){
  List list = dataSource.getGlist();
  request.setAttribute("list",list);
  request.setAttribute("operation","gd");
  }
  request.setAttribute("pageListSize",pageListSize); 

  return new ModelAndView(getCustomUrl());

3.绑定数据

  <c:if test="${operation == 'gd'}">
  <c:if test="${!empty list}">
   <div style="height:680;width:100%;overflow:auto;">
   <table bgcolor="#6F9DD9" border="0" width="100%" cellpadding="0"
    cellspacing="0">
    <tr>
    <td colspan="4" align=center bgcolor=red>
    工单列表
    </td>
    </tr>
    <tr>
     <td>
      <display:table id="dept" name="list" pagesize="${pageListSize}" class="table_changecolor" style="width:100%" cellspacing="1"
       requestURI="${path}/user/list.htm" decorator="com.ultrapower.test.web.Wrapper">
              <tr  class="even">
              <td>
       <display:column title="ID" property="deptId"
        sortable="true" style="width:30%;cursor: hand" class="content_back1"/>
        </td>
        </tr>
                 </table>
       <input type="button"  value=" 返回 "
       οnclick="invokeIndxe();"/>
   </div>
  </c:if>
  </c:if>

自此就可以使用displaytag进行应用的分页显示了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值