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 ...
随机推荐
- OpenGL 透视投影推导图解
有它足够了,转载自:http://blog.sina.com.cn/s/blog_73428e9a0102v920.html
- re正则表达式公式讲解3
1.分组匹配 用()把需要分组的类型括起来,如下 import re m = re.search("([a-z]+)([0-9]+)","alex123" ...
- vue-cli下配置项目访问ip和服务器ip
一.配置项目访问ip,让本次代码支持localhost以外的ip地址访问模式:修改里的host配置,代码如下. 修改完记得 "npm run dev"重启服务. 二.在本地架设服务 ...
- 关于对象.style currentstyle 的区别
对象.style的方式只能获取行内写法的样式,但是外部引入的或者写在head里面的就无法获取,只能用currentstyle.
- arttemplate模板引擎有假数据返回数据多层内嵌的渲染方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 如何使用xftp工具在Windows与Linux之间传输文件
如何使用xftp工具在Windows与Linux之间传输文件 整理者:vashon 声明:感谢开源社区 xftp工具是一款SFTP,FTP文件传输软件,可在Windows pc与Unix/Linux之 ...
- Selenium私房菜系列--总章
前言 在这段期间,我一直在找关于服务器的端测试方案,自动化工具等等,无意间我发现了Selenium这个工具.在试用一段时间后,觉得Selenium确实是一个很不错的Web测试工具.在和强大的QTP比较 ...
- prevent to do sth 与 prevent sb (from) doing 用法
prevent to do sth 如: Do not water in before making a turn every time 9 days, make wilting of its bra ...
- Chrome开发者工具关于网络请求的一个隐藏技能
这个隐藏技能的背景是,最近出于学习目的,我写了一个百度贴吧的网络爬虫,专门爬取一些指定主题的贴吧帖子. 抓取帖子用的JavaScript函数如下: function getPostByAJAX(req ...
- 原创:Nginx反向代理实战部署
均衡负载服务器 10.0.0.9 [root@web03 conf]# vim nginx.conf worker_processes 1; events { worker_connections ...