JSP:
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib prefix="ec" uri="http://www.ecside.org" %>
<%@ page isELIgnored="false"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test ECtable 数据库分页</title>
<link rel="stylesheet" type="text/css" href="ecside/css/ecside_style.css" />
<script type="text/javascript" src="ecside/js/ecside.js" ></script>
<script type="text/javascript" src="ecside/js/ecside_msg_utf8_cn.js" ></script>
<script type="text/javascript" src="ecside/js/prototype_mini.js" ></script>
</head>
<body>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="100" style="text-align:center" valign="middle" bgcolor="#f7f7f7">
<ec:table items="list" var="list"
retrieveRowsCallback="limit"
sortRowsCallback="limit"
filterRowsCallback="limit"
action="XXX.action"
editable="false"
width="100%"
listWidth="100%"
classic="true"
doPreload="false"
useAjax="true"
resizeColWidth="false"
batchUpdate="true"
nearPageNum="0"
toolbarLocation="top"
pageSizeList="10,20,50"
xlsFileName="table1.xls"
showPrint="true"
filterable="false"
>
<ec:row style="text-align:center">
<ec:column width="5%" property="_0" title="序号" value="${GLOBALROWCOUNT}" style="text-algin:center" editable="false"/>
<ec:column width="40%" property="userid" title="用户标识" style="text-align:center" editable="false" sortable="true"/>
<ec:column width="40%" property="username" title="用户姓名" style="text-align:center" editable="false" sortable="true"/>
</ec:row>
<c:if test="${msg != null}">
<ec:extendrow>
<tr><td colspan="3" style="text-align:center"><strong><font face='宋体' color='#5b92fa'><c:out value="${msg}"/></font></strong></td></tr>
</ec:extendrow>
</c:if>
</ec:table><br>
</td>
</tr>
</table>
</body>
<script type="text/javascript">
function myrefresh()
{
ECSideUtil.reload('ec');
setTimeout('myrefresh()',10000); //指定1秒刷新一次 1000=1秒
}
setTimeout('myrefresh()',1000); //指定1秒刷新一次 1000=1秒
</script>
</html>
<!-- 接收已经经过数据库分页处理的List , 必须做设置 retrieveRowsCallback="limit" sortRowsCallback="limit" filterRowsCallback="limit" -->
POJO:
public class TestVO {
private String userid;//用户标识
private String username;//用户姓名
//分页用
private int startRow;
private int endRow;
private String order;
private String sort;
public int getEndRow() {
return endRow;
}
public void setEndRow(int endRow) {
this.endRow = endRow;
}
public String getOrder() {
return order;
}
public void setOrder(String order) {
this.order = order;
}
public String getSort() {
return sort;
}
public void setSort(String sort) {
this.sort = sort;
}
public int getStartRow() {
return startRow;
}
public void setStartRow(int startRow) {
this.startRow = startRow;
}
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
ACTION:
public class TestAction extends ActionSupport {
private MailService mailService;
public TestService getTestService() {
return testService;
}
public void setTestService testService;{
this.testService;= testService;
}
public String searchTestList() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
TestVO vo=new TestVO();
Limit limit = RequestUtils.getLimit(request);
String sort=limit.getSort().getProperty();
String order=limit.getSort().getSortOrder();
int totalRows = RequestUtils.getTotalRowsFromRequest(request);
if (totalRows < 0) {
totalRows = mailService.countGetTestList(vo);
}
limit.setRowAttributes(totalRows, 20);
int offset = 0;
int[] rowStartEnd = new int[] { limit.getRowStart() + offset,limit.getRowEnd() + offset };
if (rowStartEnd[1] == 0) {
rowStartEnd[1] = 20;
}
vo.setStartRow(rowStartEnd[0]);
vo.setEndRow(rowStartEnd[1]);
vo.setOrder(order);
vo.setSort(sort);
List list = testService.getTestList(vo);
if(!list.isEmpty()){
request.setAttribute("list", list);
}else{
request.setAttribute("msg", "没有符合条件的记录!");
}
return SUCCESS;
}
}