<%@taglib uri="/WEB-INF/extremecomponents" prefix="ec"%>
http://blog.csdn.net/hobbypei/article/details/6722488 说的非常详细,自己写下,备忘以后用
<form method="post" name="technicianFrm" action="<%= path%>/queryDeveloperList.action"> <div id="list_menu" > <div class="nav1"> <div class="left">机构:<input name="" type="text" size="10" height="25" /> 关键字:<input name="" type="text" size="20" height="25"/> </div> <div class="right"><input name="serch" onClick=""type="image" src="<%=path %>/appstar/manage/images/serch2.png"><input name="and" onClick=""type="image" src="<%=path %>/appstar/manage/images/and.png"> </div> </div> </div> <!-- sortable,filterable,rowsDisplayed 可以在extremetable.properties统一设置 --> <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td> <ec:table cellspacing="0" cellpadding="0" border="0" action="${pageContext.request.contextPath}/queryDeveloperList.action" items="allUserList" var="arr" imagePath="${pageContext.request.contextPath}/appstar/manage/images/table/*.gif" width="100%" rowsDisplayed="10" form="technicianFrm" sortable="true" filterable="true" > <ec:exportCsv fileName="DepositHistory.csv" tooltip="CSV Download" /> <ec:exportXls fileName="listuser.xls" tooltip="Export Excel"/> <ec:row> <ec:column property="id" cell="rowCount" title="序号" /> <ec:column property="userId" title="userId"></ec:column> <ec:column property="menuNo" title="MenuNo"></ec:column> </ec:row> </ec:table> </td> </tr> </table> </form>
如果数据量大,需要分页,需要这个类 ExtremeTablePage /** * ExtremeTablePage.java * com.zte.appstar.manage.util * * Function: TODO * * ver date author * ────────────────────────────────── * Aug 6, 2012 程仁银 * * Copyright (c) 2012, All Rights Reserved. */ package com.zte.appstar.manage.util; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.extremecomponents.table.context.Context; import org.extremecomponents.table.context.HttpServletRequestContext; import org.extremecomponents.table.limit.Limit; import org.extremecomponents.table.limit.LimitFactory; import org.extremecomponents.table.limit.Sort; import org.extremecomponents.table.limit.TableLimit; import org.extremecomponents.table.limit.TableLimitFactory; /** * ClassName:ExtremeTablePage * Project: * Company: ZTE * * @author 程仁银 * @version * @since Ver 1.1 * @Date Aug 6, 2012 11:30:08 AM * @see */ @SuppressWarnings("unchecked") public final class ExtremeTablePage { /** * 最大记录数. */ public static final int MAX_PAGE_SIZE = 1000000000; public static final int defaultPageSize = 10; /** * 工具类的私有构造方法. */ private ExtremeTablePage() { } /** * 根据DEFAULT_PAGE_SIZE获得数据. * * @param request 请求 * @return Limit 封装的数据 */ public static Limit getLimit(HttpServletRequest request) { return getLimit(request, defaultPageSize); } /** * 从request构造Limit对象实例. * Limit的构造流程比较不合理,为了照顾export Excel时忽略信息分页,导出全部数据 * 因此流程为程序先获得total count, 再使用total count 构造Limit,再使用limit中的分页数据查询分页数据 * 而SS的page函数是在同一步的,无法拆分,再考虑到首先获得的totalCount * * @param request 请求 * @param defaultPageSize 页面记录数 * @return Limit 封装的数据 */ public static Limit getLimit(HttpServletRequest request, int defaultPageSize) { Context context = new HttpServletRequestContext(request); LimitFactory limitFactory = new TableLimitFactory(context); TableLimit limit = new TableLimit(limitFactory); limit.setRowAttributes(MAX_PAGE_SIZE, defaultPageSize); return limit; } /** * 将Limit中的排序信息转化为Map{columnName,升序/降序}. * @param limit 封装的页面信息 * @return Map 排序信息 */ public static Map getSort(Limit limit) { Map sortMap = new HashMap(); if (limit != null) { Sort sort = limit.getSort(); if ((sort != null) && sort.isSorted()) { sortMap.put(sort.getProperty(), sort.getSortOrder()); } } return sortMap; }}
public String queryDeveloperList() { System.out.println("############# queryDeveloperList #############"); Limit limit = ExtremeTablePage.getLimit(ServletActionContext.getRequest(),10); System.out.println("limit = "+limit);
org.extremecomponents.table.limit.TableLimit@f7821d[rowStart=20,rowEnd=30,currentRowsDisplayed=10,page=3,totalRows=1000000000,exported=false,sort=org.extremecomponents.table.limit.Sort@17f7bf6[alias=<null>,property=<null>,sortOrder=<null>],filterSet=org.extremecomponents.table.limit.FilterSet@a37512[action=<null>]]
public String queryDeveloperList() { System.out.println("############# queryDeveloperList #############"); Limit limit = ExtremeTablePage.getLimit(ServletActionContext.getRequest(),10); Sort sort = limit.getSort(); String columnSort = sort.getProperty(); System.out.println("limit = "+limit); Map<String,Object> param1 = new HashMap<String,Object>(); param1.put("eq,userId", "superstar"); System.out.println("sort.getSortOrder() = "+sort.getSortOrder()); if(sort.getSortOrder()!=null){ param1.put("order,"+columnSort,sort.getSortOrder()); } for(Filter f:limit.getFilterSet().getFilters()) { System.out.println(f.getProperty()+" "+f.getValue()); param1.put("like,"+f.getProperty(),f.getValue()); } List<UserPowerT> countList1 = this.userManageService.getObjListByParameter(UserPowerT.class, param1); Map<String,Object> param2 = new HashMap<String,Object>(); param2.put("eq,userId", "superstar"); if(sort.getSortOrder()!=null){ param2.put("order,"+columnSort,sort.getSortOrder()); } for(Filter f:limit.getFilterSet().getFilters()) { System.out.println(f.getProperty()+" "+f.getValue()); param2.put("like,"+f.getProperty(),f.getValue()); } List<UserPowerT> countList2 = this.userManageService.getListByPage(UserPowerT.class, param2,(limit.getPage()-1)*limit.getCurrentRowsDisplayed(),limit.getCurrentRowsDisplayed()); /*List<UserPowerT> allUserList = this.userManageService.queryUserListDemo(limit.getPage(),limit.getCurrentRowsDisplayed(),"superstar",columnSort,sortOrder);*/ ServletActionContext.getRequest().setAttribute("allUserList",countList2); ServletActionContext.getRequest().setAttribute("totalRows",countList1.size()); return SUCCESS; }