Posted on 2007-04-25 16:37
G_G 阅读(813)
评论(0) 编辑 收藏
我先给出 jsp
<%@ taglib prefix="ec" uri="/WEB-INF/extremecomponents.tld" %>
<%@ taglib prefix="c" uri="/WEB-INF/c.tld" %>
<%@ page language = "java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<head>
<link rel ="stylesheet" type ="text/css" href ="<c:url value="/extremecomponents.css" /> ">
</head>
<ec:table
items="table"
var="result"
retrieveRowsCallback="limit" //关键 申明
action="${pageContext.request.contextPath}/list.do"
imagePath="${pageContext.request.contextPath}/images/table/*.gif"
title="查询结果"
width="100%"
rowsDisplayed="5"
>
<ec:row>
<ec:column property="name" />
<ec:column property="pass" />
</ec:row>
</ec:table>
提交给的Action
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
ListForm listForm = (ListForm) form;
Context context = new HttpServletRequestContext(request);
LimitFactory limitFactory = new TableLimitFactory(context);
TableLimit limit = new TableLimit(limitFactory);
limit.setRowAttributes(Integer.MAX_VALUE, 5); //关键得出 extremecomponents limit
PageBean page = new PageBean();
System.out.println(limit.getCurrentRowsDisplayed()+":limit");
page.setPageSize(limit.getCurrentRowsDisplayed()); //ec通过limit对象传递pageSize给PageBean
page.setPage(limit.getPage());//ec通过limit对象传递pageNo给PageBean
request.setAttribute("table",page.getList());
request.setAttribute("totalRows", new Integer(page.getCount()));
return mapping.findForward("list");
}
提交 bean
package test;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
public class PageBean {
static ArrayList arr1 = new ArrayList();
static {
for(int i=0;i<1000;i++){
Map map = new Hashtable();
map.put("name",i+"liukaiyi");
map.put("pass",i+"123");
arr1.add(map);
}
}
//仿照 数据 *************************************
private int count = 1000; // 记录总数
private int pageSize = 10; // 每页显示记录数
private int pageCount = 0; // 总页数
private int page = 1; // 当前页数
public int getCount() {
return count;
}
public void setCount(int count) {
if (pageSize != 0) {
pageCount = count / pageSize;
if (count % pageSize != 0) {
pageCount++;
}
}
this.count = count;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public List getList(){ //提交 给 List 显示的 数据********************
int st = (getPage()-1)*getPageSize()-1 ;
int end = st+getPageSize() +1;
System.out.println("bean "+st+":"+end);
List arr = arr1.subList(st,end);
return arr ;
}
}