我們非常高興的宣布,EasyJWeb-1.1今日正式對外發布,這個版本主要對EasyJWeb的Ajax支持作較大的改進。主要包括下面的內容:
1、在EasyJWeb Tools中增加了一套Rich Component組件,可以與其它客戶端Ajax框架比如ExtJS等集成開發RIA應用。
2、修改了遠程腳本調用引擎,使得性能比上一版本前提升了近2倍,詳見http://www.easyjf.com/blog/html/20080103/1015816.html;
3、多國語言功能增加了對 xml格式屬性文件的支持,http://jira.easyjf.com/browse/EASYJWEB-33。
4、增加從服務器輸入JSon數據對象的快捷支持。
5、提供了更多的EastJWeb實例應用,詳見http://easyjweb.demo.easyjf.com/。
6、修正了這兩個月來大家提出的Bug及調整了一些功能,詳細見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改進作簡單介紹。
一、EasyJWeb Rich Component
EasyJWeb 1.1版提供了一套富客戶端組件,也就是Rich Componet,可以用來與ExtJS等配合快速開發出基于Ajax的RIA應用。不再需要寫煩瑣的javascript,直接用java就能寫出漂亮的基于ExtJS等客戶端框架的Ajax應用,詳見示例http://wlr2.easyjf.com/。
比如只需要下面的Action代碼:
public class SimpleAction extends RichComponentAction {
public Page doGrid() {
ViewPort view = new ViewPort();
GridPanel grid = new GridPanel("grid", "數據表格",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將會得到一個還不錯的樹:

如何實現一個添刪改查、分頁呢?看下面的代碼:
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", "網址" },
{ "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將會得到一個添刪改查及分頁的界面,點擊“添加”、“修改”、“刪除”、“刷新”等按鈕可以執行相應的操作,如下圖所示:

二、其它Ajax支持的改進及完善
1、在以前EasyJWeb的Ajax支持引擎基礎上,對遠程腳本調用引擎中的腳本engine.js作了調整,使得回調函數可以選擇作用域scope。
服務器業務組件:
public class PersonServiceImpl {
/**
* 得到服務器當前時間
* @return
*/
public Date getTime() {
return new Date();
}
}
Bean配置文件:
<bean name="PersonService" class="easyjweb.demo.service.impl.PersonServiceImpl" />
在javascript中調用:
var s="作用域2";
var o=new function()
{
this.s="作用域1";
}
function callback(d)
{
alert("服務器時間:"+d);
alert(this.test);
}
客戶端讀取服務器端時間的代碼:
PersonService.getTime(callback);//沒有使用作用域
PersonService.getTime(callback,new o());//回調函數在o實例作用域中使用域
PersonService.getTime(callback,window);//回調函數在window作用域中執行
2、增加向客戶端輸出JSon對象數據的快速方法。
public Page doList(WebForm form) {
QueryObject qo = form.toPo(QueryObject.class);
IPageList pageList = service.getLinkBy(qo);
form.jsonResult(pageList);
return Page.JSONPage;
}
上面的代碼實現把服務器端的pageList對象轉換成JSON數據對象,并給客戶端返回這個JSon數據對象。
客戶端可以這樣使用:
var s=eval(req.responseText);
alert(s.rowCount);
for(var i=0;ialert(s.result[i].title);
3、另外還對表單ajax提交等作了其它一些調整,詳細請參考最新的api文檔。
posted on 2008-02-20 10:22
簡易java框架 閱讀(1847)
評論(2) 編輯 收藏