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 ...
随机推荐
- Ionic之ui-sref引入图片,图片部分挡住解决方案
ionic图片设置大小跟图片像素相同,但是使用ui-sref="parkInfo"上半部分图片会挡住,增加height的高度,就可以显示原本图片 页面: <ion-conte ...
- Dom 获取、Dom动态创建节点
一.Dom获取 1.全称:Document Object Model 文档对象模型 2.我们常用的节点类型 元素(标签)节点.文本节点.属性节点(也就是标签里的属性). 3.docum ...
- vue中的事件监听之——v-on vs .$on
跟着视频中老师的教学视频学vue的时候,看很多时候都用@(v-on)来监听子级emit的自定义事件,但在bus总线那块,又用.$on来监听bus自身emit的事件,v-on之间似乎相似但又不同,今天对 ...
- Android利用融云做异地登录提醒
在RongCloudEvent下找到onChanged方法 @Override public void onChanged(ConnectionStatus connectionStatus) { s ...
- 第一章 熟悉Objective -C 编写高质量iOS与OS X代码的52 个有效方法
第一章 熟悉Objective -C 编写高质量iOS与OS X代码的52 个有效方法 第一条: 了解Objective-C 语言的起源 关键区别在于 :使用消息结构的语言,其运行时所应执行 ...
- 8 Explicit Animations 指明的动画 笔记
8 Explicit Animations 指明的动画 笔记 If you want something done right, do it yourself. 如果你想让事情做好,那就自动来 ...
- Junit测试集锦
Junit测试集锦 前言: 一个程序从设计很好的状态开始,随着新的功能不断地加入,程序逐渐地失去了原有的结构,最终变成了一团乱麻.所以在开发过程中,对于程序员来说,测试是非常重要的.言归正传,开始Ju ...
- Kali 2017.3开启VNC远程桌面登录
通过启用屏幕共享来开启远程桌面登录,开启后需要关闭encryption,否则会出现无法连接的情况.关闭encryption可以使用系统配置工具dconf来完成.所以先安装dconf-editor. 更 ...
- 【OpenCV】motion blur 的简单实现
先推荐界面比较丑,但是还不错的在线图片处理网站: http://www168.lunapic.com/editor/ 由于最近在做毕设了,结合前面关于图像处理和机器学习的操作,想做一些好玩的东西,其中 ...
- uva10735 Euler Circuit
题外话:很多混合图问题可以转化为有向图问题(将无向边拆为两条有向边) 本题不行,因为只能经过一次 这种问题能想到网络流.. 复习欧拉回路:入度==出度 和uva1380有点相似,要先给无向边定向.原图 ...