我們非常高興的宣布,EasyJWeb-1.1今日正式對外發(fā)布,這個版本主要對EasyJWeb的Ajax支持作較大的改進(jìn)。主要包括下面的內(nèi)容:
1、在EasyJWeb Tools中增加了一套Rich Component組件,可以與其它客戶端Ajax框架比如ExtJS等集成開發(fā)RIA應(yīng)用。
2、修改了遠(yuǎn)程腳本調(diào)用引擎,使得性能比上一版本前提升了近2倍,詳見http://www.easyjf.com/blog/html/20080103/1015816.html;
3、多國語言功能增加了對 xml格式屬性文件的支持,http://jira.easyjf.com/browse/EASYJWEB-33。
4、增加從服務(wù)器輸入JSon數(shù)據(jù)對象的快捷支持。
5、提供了更多的EastJWeb實例應(yīng)用,詳見http://easyjweb.demo.easyjf.com/。
6、修正了這兩個月來大家提出的Bug及調(diào)整了一些功能,詳細(xì)見jira.easyjf.com。
7、完善了入門文檔,詳見wiki.easyjf.com。
源碼下載:ftp://ftp1.easyjf.com/easyjweb/easyjweb-1.1/easyjweb-1.1.zip
在線示例:http://easyjweb.demo.easyjf.com
在線文檔:http://wiki.easyjf.com/display/wiki/EasyJWeb
這里對Rich Component及Ajax改進(jìn)作簡單介紹。
一、EasyJWeb Rich Component
EasyJWeb 1.1版提供了一套富客戶端組件,也就是Rich Componet,可以用來與ExtJS等配合快速開發(fā)出基于Ajax的RIA應(yīng)用。不再需要寫煩瑣的javascript,直接用java就能寫出漂亮的基于ExtJS等客戶端框架的Ajax應(yīng)用,詳見示例http://wlr2.easyjf.com/。
比如只需要下面的Action代碼:
public class SimpleAction extends RichComponentAction { public Page doGrid() { ViewPort view = new ViewPort(); GridPanel grid = new GridPanel("grid", "數(shù)據(jù)表格",500,100); grid.setColumns(new String[]{"id","姓名","出生日期","email"}); view.add(grid); this.addComponent(view); return componentPage; } }
訪問simple.ejf?cmd=grid將會得到一個非常漂亮的表格:
public Page doTree() { ViewPort view = new ViewPort(); TreePanel tree=new TreePanel("tree","簡單的樹",200); TreeNode root=new TreeNode("root","根"); root.add(new TreeNode("c1","孩子1")); root.add(new TreeNode("c2","孩子2")); root.getChildNodes().get(1).add(new TreeNode("c3","孫子")); tree.setRoot(root); view.add(tree); this.addComponent(view); return componentPage; }
訪問simple.ejf?cmd=tree將會得到一個還不錯的樹:
如何實現(xiàn)一個添刪改查、分頁呢?看下面的代碼:
public Page doCrud() { ViewPort view = new ViewPort("fit"); CrudPanel crud = new SimpleCrud(); view.add(crud); this.addComponents(view); return componentPage; } public class SimpleCrud extends CrudPanel { public SimpleCrud() { super("test", "簡單測試", "link.ejf"); this.setColumns(new String[][] { { "title", "名稱" },{ "url", "網(wǎng)址" }, { "rss", "RSS" } }); this.getPagingToolbar().setDisplayInfo(true); this.getGrid().load(); } @Override public Function getCreateWin() { return new Function("return this.initWin(438,300,'連接管理');"); } @Override public Form getForm() { Form f = new Form(); f.add(new TextField("title", "主題")); f.setLazy(false); return f; } }
訪問simple.ejf?cmd=crud將會得到一個添刪改查及分頁的界面,點擊“添加”、“修改”、“刪除”、“刷新”等按鈕可以執(zhí)行相應(yīng)的操作,如下圖所示:
二、其它Ajax支持的改進(jìn)及完善
1、在以前EasyJWeb的Ajax支持引擎基礎(chǔ)上,對遠(yuǎn)程腳本調(diào)用引擎中的腳本engine.js作了調(diào)整,使得回調(diào)函數(shù)可以選擇作用域scope。
服務(wù)器業(yè)務(wù)組件:
public class PersonServiceImpl { /** * 得到服務(wù)器當(dāng)前時間 * @return */ public Date getTime() { return new Date(); } }
Bean配置文件:
<bean name="PersonService" class="easyjweb.demo.service.impl.PersonServiceImpl" />
在javascript中調(diào)用:
var s="作用域2"; var o=new function() { this.s="作用域1"; } function callback(d) { alert("服務(wù)器時間:"+d); alert(this.test); }
客戶端讀取服務(wù)器端時間的代碼:
PersonService.getTime(callback);//沒有使用作用域
PersonService.getTime(callback,new o());//回調(diào)函數(shù)在o實例作用域中使用域
PersonService.getTime(callback,window);//回調(diào)函數(shù)在window作用域中執(zhí)行
2、增加向客戶端輸出JSon對象數(shù)據(jù)的快速方法。
public Page doList(WebForm form) { QueryObject qo = form.toPo(QueryObject.class); IPageList pageList = service.getLinkBy(qo); form.jsonResult(pageList); return Page.JSONPage; }
上面的代碼實現(xiàn)把服務(wù)器端的pageList對象轉(zhuǎn)換成JSON數(shù)據(jù)對象,并給客戶端返回這個JSon數(shù)據(jù)對象。
客戶端可以這樣使用:
var s=eval(req.responseText);
alert(s.rowCount);
for(var i=0;ialert(s.result[i].title);
3、另外還對表單ajax提交等作了其它一些調(diào)整,詳細(xì)請參考最新的api文檔。