jmesa整合struts2标签分页
??原文来自 http://zghbwjl.blog.163.com/blog/static/12033667220108209424766/
?jmesa是一个集成了分页,导出,编辑,显示,排序,过滤等等功能强大的一个表格控件,但是用起来我还是有点不熟练,最近只是对分页进行了运用,其他的还有待于以后运用。下面我说一下如何使用jmesa进行分页.
??????? 我用的是jmesa3.0,struts2,jdk要在1.5以上,做了简单的分页,这里主要是为了说名怎么用jmesa。
???????? 首先下载jmesa,http://code.google.com/p/jmesa/downloads/list
???????? <%
String path = request.getContextPath();
%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="/WEB-INF/tld/jmesa.tld" prefix="jmesa" %>?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? <head>
???
??? <title>My JSP 'list_user.jsp' starting page</title>
??? <script type="text/javascript" src="http://zghbwjl.blog.163.com/blog/<%=path%>/js/jmesa/jquery-1.4.2.min.js"></script>
??? <script type="text/javascript" src="http://zghbwjl.blog.163.com/blog/<%=path%>/js/jmesa/jquery.js"></script>?
??? <script type="text/javascript" src="http://zghbwjl.blog.163.com/blog/<%=path%>/js/jmesa/jquery.jmesa.js"></script>
??? <script type="text/javascript" src="http://zghbwjl.blog.163.com/blog/<%=path%>/js/jmesa/jmesa.js"></script>??????????????
??? <link rel="stylesheet" type="text/css" href="http://zghbwjl.blog.163.com/blog/<%=path%>/css/jmesa/jmesa.css"></link>
? </head>
?
? <body>
? <form name="userForm" action="<%=path %>/users.action" method="post">
? ??? <jmesa:struts2TableModel items="${items}" id="user_table" var="bean" stateAttr="restore" >
? ??? ??? <jmesa:htmlTable width="600" caption="用户信息">
? ??? ??? ??? <jmesa:htmlRow uniqueProperty="username">
? ??? ??? ??? ??? <jmesa:htmlColumn property="username" />
? ??? ??? ??? ??? <jmesa:htmlColumn property="password"/>
? ??? ??? ??? </jmesa:htmlRow>
? ??? ??? </jmesa:htmlTable>
? ??? </jmesa:struts2TableModel>
? </form>
? <script type="text/javascript">
? ??? function onInvokeAction(id){
? ??? ??? $.jmesa.setExportToLimit(id,'');
? ??? ??? $.jmesa.createHiddenInputFieldsForLimitAndSubmit(id);
? ??? }??
? </script>
? </body>
</html>
这是页面代码,相应的引入css,js文件,同时有一个
?这是所有的需要的jar文件
下面看action:
public class UsersAction extends ActionSupport implements ServletRequestAware,ServletResponseAware {
??? /**
??? ?*
??? ?*/
??? private static final long serialVersionUID = 1L;
??? private HttpServletRequest request;
??? private HttpServletResponse response;
??? @Override
??? public void setServletRequest(HttpServletRequest request) {
??? ??? this.request=request;
??? }
??? @Override
??? public void setServletResponse(HttpServletResponse response) {
??? ??? this.response=response;
??? }
??? public String execute(){
??? ??? List items=new ArrayList();
??? ??? for(int i=0;i<20;i++){
??? ??? ??? Users users=new Users();
??? ??? ??? users.setUsername("aa"+i);
??? ??? ??? users.setPassword("pwd"+i);
??? ??? ??? items.add(users);
??? ??? }
??? ??? String id="user_table";
??? ??? TableFacade tableFacade = new TableFacadeImpl("user_table", request);
?
??????? request.setAttribute("items",items);
??????? return "success";
??? }
}