棣栧厛浠嬬粛涓涓嬬洿鎺ュ湪java浠g爜涓帶鍒剁殑鏂瑰紡錛?
- public class PaginationActionBean implements ActionBean {
-
-
- 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");
-
-
-
- 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();
-
- 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();
- }
-
- ..............
- }
public class PaginationActionBean implements ActionBean {
//姝d琛ㄧず灝嗚鍒涘緩鐨則able鐨刬d
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.
}
..............
}
涓婇潰鐨勪唬鐮佷腑鏈閲嶈鐨勫氨鏄偅涓奾tml鏂規(guī)硶錛屾鏂規(guī)硶瀹屾垚浜?jiǎn)鏁翠釜琛ㄦ牸鐨勫畾鍒跺伐浣滃Q屽寘鎷摼鎺ュ湪鍐呫傚鏋滆閲嶆柊璁劇疆姣忛〉鏄劇ず鐨勮褰曟暟錛堥粯璁ゆ瘡欏靛彲鏄劇ず15錛?0錛?00錛夛紝瑕佷箞淇敼jmesa.properties鏂囦歡錛岃涔堥氳繃java浠g爜璁劇疆銆備慨鏀歸厤緗枃浠剁殑璇濓紝鍚屾椂瑕佷慨鏀逛袱涓湴鏂癸細(xì)
limit.rowSelect.maxRows=15
html.toolbar.maxRowsDroplist.increments=15,50,100
濡傛灉淇敼錛屽繀欏繪弧瓚崇涓琛岀殑鏁板瓧蹇呴』鏄浜岃鎵鏈夋暟瀛椾腑鐨勪竴涓傜敤java浠g爜淇敼鐨勪篃瑕侀伒鐓у悓鏍風(fēng)殑鍘熷垯銆?
jsp浠g爜寰堢畝鍗曪細(xì)
- <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>
涓婇潰榪欐浠g爜涓紝闇瑕佹敞鎰忎竴涓婮S澹版槑鐨勯『搴忥紝鑰屼笖榪樿鐢蟲(chóng)槑涓涓猣orm錛屼笉鐒跺垎欏電殑鏃跺橨S浼?xì)鍑洪敊銆傝繕瑕佸姞涓婁笂闈㈢殑閭fJS浠g爜銆?
絎簩縐嶆柟寮忔槸鐩存帴閫氳繃鏍囩鐨勬柟寮忕敵鏄庯紝鍥犳闇瑕佸湪JSP澶撮儴鐢蟲(chóng)槑錛?
- <%@ taglib uri="/WEB-INF/tld/jmesa.tld" prefix="jmesa" %>
- .........
- ...............
<%@ taglib uri="/WEB-INF/tld/jmesa.tld" prefix="jmesa" %>
.........
...............
灝?{actionBean.html}鏇挎崲鎴愶細(xì)
- <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>
榪欓儴鍒嗕唬鐮佺殑浣滅敤涓庝笂闈ction鐩存帴鎿嶇旱琛ㄦ牸鐨勬柟寮忎竴鏍鳳紝鍙槸鎶婂伐浣滆漿縐誨埌JSP涓傚彧鏄笂闈㈢殑${items}琛ㄧず涓涓皢瑕佹樉紺虹殑collection錛屼笉鐢ㄥ啀浣跨敤瀛楃涓茬殑鏂瑰紡鏄劇ず銆傚鏋滀袱縐嶆柟寮忛兘鐢ㄧ殑璇濓紝鍒欎互JSP涓殑鏂瑰紡涓哄噯銆?
jmesa鐨勯厤緗枃浠跺凡緇忛泦鎴愬湪JAR涓紝濡傛灉闇瑕佹敼鍙橈紝鍙互灝嗘鏂囦歡澶嶅埗鍑烘潵錛屾敼鍙樺叾鍐呭錛岀劧鍚庡湪web.xml閲嶆柊鎸囧畾鍏惰礬寰勶細(xì)
- <context-param>
- <param-name>jmesaPreferencesLocation</param-name>
- <param-value>WEB-INF/jmesa.properties</param-value>
- </context-param>

]]>