标签:
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.
}
..............
}
<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>
<%@ taglib uri="/WEB-INF/tld/jmesa.tld" prefix="jmesa" %> ......... ...............
<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>
<context-param> <param-name>jmesaPreferencesLocation</param-name> <param-value>WEB-INF/jmesa.properties</param-value> </context-param>
标签:
原文地址:http://www.cnblogs.com/wnlja/p/4222018.html