jmesa应用
需要用到的组件有点多,如附件图所示。需要注意的是,web层用了Stripes,个人认为此框架很好,源码也写得很好。2.4.5的ZIP包中,有大多数文件,但是有些也没有,如slf4j与jquery等。
jmesa分页的方式有两种,一种是通过java代码直接控制,第二种是通过标签来控制。
首先介绍一下直接在java代码中控制的方式:
- public class PaginationActionBean implements ActionBean {
- //此id表示将要创建的table的id
- private String id = "user_table";
- private ActionBeanContext context;
- private String html;
- public String getHtml() {
- return html;
- }
- public void setHtml(String html) {
- this.html = html;
- }
- ........
- @DefaultHandler
- public Resolution display() {
- TableFacade tableFacade = TableFacadeFactory.createTableFacade(id, this
- .getContext().getRequest());
- addItems(tableFacade);
- html = html(tableFacade);
- ForwardResolution resolution = new ForwardResolution("/jsp/page.jsp");
- return resolution;
- }
- private void addItems(TableFacade tableFacade) {
- tableFacade.setItems(FillListData.getData());
- }
- private String html(TableFacade tableFacade) {
- tableFacade.setColumnProperties("name", "password", "deleteUser");
- HtmlTable table = (HtmlTable) tableFacade.getTable();
- table.setCaption("用户列表");
- table.getTableRenderer().setWidth("600px");
- HtmlRow row = table.getRow();
- HtmlColumn name = row.getColumn("name");
- name.setTitle("名字");
- HtmlColumn password = row.getColumn("password");
- password.setTitle("密码");
- HtmlColumn delete = row.getColumn("deleteUser");
- delete.setTitle("删除");
- delete.setWidth("100px");
- // Using an anonymous class to implement a custom editor.
- // 用于演示在表格中增加超链接
- name.getCellRenderer().setCellEditor(new CellEditor() {
- public Object getValue(Object item, String property, int rowcount) {
- Object value = new BasicCellEditor().getValue(item, property,
- rowcount);
- HtmlBuilder html = new HtmlBuilder();
- html.a().href().quote().append("http://baidu.com").quote()
- .close();
- html.append(value);
- html.aEnd();
- return html.toString();
- }
- });
- delete.getCellRenderer().setCellEditor(new CellEditor() {
- public Object getValue(Object item, String property, int rowcount) {
- HtmlBuilder html = new HtmlBuilder();
- // 取得每一行的id号
- Object user = ItemUtils.getItemValue(item, "name");
- String js = " onclick='javascript:del(\"user\"," + user + ") '";
- html.a().append(js).href().quote().append(
- getContext().getRequest().getContextPath()
- + "/Pagination.action?delete&user=" + user)
- .quote().close();
- html.append("删除");
- html.aEnd();
- return html.toString();
- }
- });
- return tableFacade.render(); // Return the Html.
- }
- ..............
- }
public class PaginationActionBean implements ActionBean { //此id表示将要创建的table的id
private String id = "user_table";
private ActionBeanContext context;
private String html; public String getHtml() {
return html;
}
public void setHtml(String html) {
this.html = html;
}
........ @DefaultHandler
public Resolution display() {
TableFacade tableFacade = TableFacadeFactory.createTableFacade(id, this
.getContext().getRequest()); addItems(tableFacade);
html = html(tableFacade);
ForwardResolution resolution = new ForwardResolution("/jsp/page.jsp");
return resolution;
} private void addItems(TableFacade tableFacade) {
tableFacade.setItems(FillListData.getData());
} private String html(TableFacade tableFacade) { tableFacade.setColumnProperties("name", "password", "deleteUser"); HtmlTable table = (HtmlTable) tableFacade.getTable();
table.setCaption("用户列表");
table.getTableRenderer().setWidth("600px"); HtmlRow row = table.getRow(); HtmlColumn name = row.getColumn("name");
name.setTitle("名字"); HtmlColumn password = row.getColumn("password");
password.setTitle("密码"); HtmlColumn delete = row.getColumn("deleteUser");
delete.setTitle("删除");
delete.setWidth("100px"); // Using an anonymous class to implement a custom editor.
// 用于演示在表格中增加超链接
name.getCellRenderer().setCellEditor(new CellEditor() {
public Object getValue(Object item, String property, int rowcount) {
Object value = new BasicCellEditor().getValue(item, property,
rowcount);
HtmlBuilder html = new HtmlBuilder();
html.a().href().quote().append("http://baidu.com").quote()
.close();
html.append(value);
html.aEnd();
return html.toString();
}
}); delete.getCellRenderer().setCellEditor(new CellEditor() {
public Object getValue(Object item, String property, int rowcount) { HtmlBuilder html = new HtmlBuilder();
// 取得每一行的id号
Object user = ItemUtils.getItemValue(item, "name");
String js = " onclick='javascript:del(\"user\"," + user + ") '";
html.a().append(js).href().quote().append(
getContext().getRequest().getContextPath()
+ "/Pagination.action?delete&user=" + user)
.quote().close();
html.append("删除");
html.aEnd();
return html.toString();
}
}); return tableFacade.render(); // Return the Html.
} ..............
}
上面的代码中最重要的就是那上html方法,此方法完成了整个表格的定制工作,包括链接在内。如果要重新设置每页显示的记录数(默认每页可显示15,50,100),要么修改jmesa.properties文件,要么通过java代码设置。修改配置文件的话,同时要修改两个地方:
limit.rowSelect.maxRows=15
html.toolbar.maxRowsDroplist.increments=15,50,100
如果修改,必须满足第一行的数字必须是第二行所有数字中的一个。用java代码修改的也要遵照同样的原则。
jsp代码很简单:
- <script type="text/javascript"
- src="${pageContext.request.contextPath}/js/jquery.js"></script>
- <script type="text/javascript"
- src="${pageContext.request.contextPath}/js/jquery.jmesa.js"></script>
- <script type="text/javascript"
- src="${pageContext.request.contextPath}/js/jmesa.js"></script>
- <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/jmesa.css"></link>
- </head>
- <body>
- <h1>Stripes Calculator</h1>
- <form>
- ${actionBean.html}
- <script type="text/javascript">
- function onInvokeAction(id) {
- createHiddenInputFieldsForLimitAndSubmit(id);
- }
- </script>
- </form>
- </body>
<script type="text/javascript"
src="${pageContext.request.contextPath}/js/jquery.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/js/jquery.jmesa.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/js/jmesa.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/jmesa.css"></link>
</head>
<body>
<h1>Stripes Calculator</h1> <form>
${actionBean.html}
<script type="text/javascript">
function onInvokeAction(id) {
createHiddenInputFieldsForLimitAndSubmit(id);
}
</script>
</form>
</body>
上面这段代码中,需要注意一下JS声明的顺序,而且还要申明一个form,不然分页的时候JS会出错。还要加上上面的那段JS代码。
第二种方式是直接通过标签的方式申明,因此需要在JSP头部申明:
- <%@ taglib uri="/WEB-INF/tld/jmesa.tld" prefix="jmesa" %>
- .........
- ...............
<%@ taglib uri="/WEB-INF/tld/jmesa.tld" prefix="jmesa" %>
.........
...............
将${actionBean.html}替换成:
- <jmesa:tableFacade id="user_table" items="${items}" var="bean" >
- <jmesa:htmlTable width="600px">
- <jmesa:htmlRow>
- <jmesa:htmlColumn property="name"/>
- <jmesa:htmlColumn property="password" title="Last Name"/>
- </jmesa:htmlRow>
- </jmesa:htmlTable>
- </jmesa:tableFacade>
<jmesa:tableFacade id="user_table" items="${items}" var="bean" >
<jmesa:htmlTable width="600px">
<jmesa:htmlRow>
<jmesa:htmlColumn property="name"/>
<jmesa:htmlColumn property="password" title="Last Name"/>
</jmesa:htmlRow>
</jmesa:htmlTable>
</jmesa:tableFacade>
这部分代码的作用与上面action直接操纵表格的方式一样,只是把工作转移到JSP中。只是上面的${items}表示一个将要显示的collection,不用再使用字符串的方式显示。如果两种方式都用的话,则以JSP中的方式为准。
jmesa的配置文件已经集成在JAR中,如果需要改变,可以将此文件复制出来,改变其内容,然后在web.xml重新指定其路径:
- <context-param>
- <param-name>jmesaPreferencesLocation</param-name>
- <param-value>WEB-INF/jmesa.properties</param-value>
- </context-param>
<context-param>
<param-name>jmesaPreferencesLocation</param-name>
<param-value>WEB-INF/jmesa.properties</param-value>
</context-param>
- 大小: 27.3 KB
jmesa应用的更多相关文章
- 使用 Spring 2.5 TestContext 测试DAO层
资源准备: mysql5.0 spring-2.5 hibernate-3.2 junit-4.jar 创建表 DROP TABLE IF EXISTS `myproject`.`boys`; ...
- Java开源JSP标签库
01displytag 与Struts结合使用最出名的一个tag主要是显示表格数据很漂亮.完善. 02cewolf tag 用来在web上显示复杂图形报表的一个jsp tag. 03Loading T ...
随机推荐
- C#基础学习3
运算符,表达式!
- [转]MVC 检测用户是否已经登录
本文转自:http://blog.csdn.net/jayzai/article/details/41252137 当我们访问某个网站的时候需要检测用户是否已经登录(通过Session是否为null) ...
- AJPFX分享eclipse自动生成java注释方法
设置方法介绍:eclipse中:Windows->Preferences->Java->Code Style->Code Template->Comments,然后对应的 ...
- AJPFX关于枚举,泛型详解
枚举类型是JDK5.0的新特征.Sun引进了一个全新的关键字enum来定义一个枚举类.下面就是一个典型枚举类型的定义:public enum Color{RED,BLUE,BLACK,YELLOW,G ...
- [转]Android APK签名原理及方法
准备知识:数据摘要 这个知识点很好理解,百度百科即可,其实他也是一种算法,就是对一个数据源进行一个算法之后得到一个摘要,也叫作数据指纹,不同的数据源,数据指纹肯定不一样,就和人一样. 消息摘要算法(M ...
- postgresql版sde(10.4.1)安装说明
从ArcGIS 10.3开始,彻底没有了sde的安装包,安装sde数据库需要先安装arcgis desktop,通过arccatalog建数据库,同时也不能建sde服务,只能使用直连 以下演示在sde ...
- Kotlin学习的一些笔记
Introduction 写在前面 关于本书 这本书适合你吗? 关于作者 介绍 什么是Kotlin? 我们通过Kotlin得到什么 准备工作 Android Studio 安装Kotlin插件 创建一 ...
- http://bbs.chinaunix.net/thread-1463276-1-1.html
http://bbs.chinaunix.net/thread-1463276-1-1.html
- JS实现让其他浏览器自动转至微信浏览器打开链接
//判断是否是pc function is_pc() { var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUser ...
- linux_2
mac和linux上默认安装着SSH客户端,Windows上需要自己安装个软件. Windows下SSH客户端的安装:建议从官方网站下载正式程序安装(免费) Putty:https://www.chi ...