本站首页    管理页面    写新日志    退出


«October 2025»
1234
567891011
12131415161718
19202122232425
262728293031


公告
本博客在此声明所有文章均为转摘,只做资料收集使用。并无其他商业用途。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:210
评论数量:205
留言数量:-19
访问次数:924652
建立时间:2007年5月10日




[EXT2.0]用GWTProxy获取服务端分页
文章收藏,  网上资源,  软件技术,  电脑与网络

李小白 发表于 2008/4/23 9:55:44

Print view Previous topic :: Next topic  Author Message Xral  Post subject: How could I get remote data for paging grid in a GWT way? 500)this.width=500'>Posted: Mon Mar 03, 2008 4:25 am  500)this.width=500'>Joined: Mon Mar 03, 2008 3:35 amPosts: 1 Hi there!In the sample, Grid with Remote Paging, a ScriptTagProxy is used to get data from remote site. But, could I use a RPC, the GWT way, to get data from the server? Could you please give me a sample to follow? Thanks! Back to top  500)this.width=500'>     500)this.width=500'> urban.novak  Post subject: Re: How could I get remote data for paging grid in a GWT way? 500)this.width=500'>Posted: Mon Mar 03, 2008 7:06 am  500)this.width=500'>Joined: Tue Feb 26, 2008 9:58 amPosts: 35 Well, you could create new implementation of dataproxy, that forwards load request from native javascript to gwt code. I've done it this way in project i'm working on. I could paste (it's only about 70 lines of code) here source code, but Sanjiv wouldn't be happy, because he is selling similar functionality in GWT-Plus. Back to top  500)this.width=500'>     500)this.width=500'> urban.novak  Post subject: Re: How could I get remote data for paging grid in a GWT way? 500)this.width=500'>Posted: Tue Mar 04, 2008 4:20 am  500)this.width=500'>Joined: Tue Feb 26, 2008 9:58 amPosts: 35 I've checked features of GWTPlus and it offers much much more than my implementation of GWTProxy, I hope I wont ruin any business of SJ.So, here it is.Updated version below.GWTProxy is designed to work with ArrayReader. Code: Store store = new Store(new MyGWTProxy(), new ArrayReader(recordDef), true);Last edited by urban.novak on Wed Mar 05, 2008 4:45 am, edited 1 time in total. Back to top  500)this.width=500'>     500)this.width=500'> Lajcik  Post subject: Re: How could I get remote data for paging grid in a GWT way? 500)this.width=500'>Posted: Tue Mar 04, 2008 8:10 am  500)this.width=500'>Joined: Tue Mar 04, 2008 7:52 amPosts: 6 Many thanks for this, it really saved me the pain of figuring out how to make something similar 500)this.width=500'> Much appreciated.One detail tho - Code: protected void loadResponse(JavaScriptObject o, boolean success, int totalRecords, String[][] data){        loadResponse(o, true, totalRecords,  JavaScriptObjectHelper.convertToJavaScriptArray(data));            }could accept Object[][] as data, which is useful if you have dates for example Back to top  500)this.width=500'>     500)this.width=500'> dragos  Post subject: Re: How could I get remote data for paging grid in a GWT way? 500)this.width=500'>Posted: Tue Mar 04, 2008 9:27 am  500)this.width=500'>Joined: Tue Mar 04, 2008 9:23 amPosts: 1 I apreciate verry much the ideea but coud you tell me what's the real type of mfd.data. How is my RPC data wrapped into mfd.data as i see tha here is of JavascriptObject type.QUOTE[ loadResponse(o, true, mfd.totalRecords, mfd.data); ]Thanks! urban.novak wrote: I've checked features of GWTPlus and it offers much much more than my implementation of GWTProxy, I hope I wont ruin any business of SJ.So, here it is. Code: package com.gwtext.client.data;import com.google.gwt.core.client.JavaScriptObject;import com.gwtext.client.util.JavaScriptObjectHelper;public abstract class GWTProxy extends DataProxy{        public GWTProxy(){        jsObj = create();    }    protected native JavaScriptObject create() /*-{        var o=new $wnd.Ext.ux.data.GWTProxy();        o.gwtmem=this;        return o;    }-*/;        private static native void init()/*-{        $wnd.Ext.namespace("Ext.ux");        $wnd.Ext.namespace("Ext.ux.data");        $wnd.Ext.ux.data.GWTProxy = function(){            $wnd.Ext.ux.data.GWTProxy.superclass.constructor.call(this);        };                        $wnd.Ext.extend($wnd.Ext.ux.data.GWTProxy, $wnd.Ext.data.DataProxy, {            load : function(params, reader, callback, scope, arg){                    var  o = {                        params : params || {},                        request: {                            callback : callback,                            scope : scope,                            arg : arg                        },                        reader: reader,                        callback : this.loadResponse,                        scope: this                    };                     this.gwtmem.@com.gwtext.client.data.GWTProxy::load(IILcom/google/gwt/core/client/JavaScriptObject;)(params.start == undefined? -1:params.start , params.limit==undefined?-1:params.limit,o);               },            loadResponse : function(o, success, totalRecords, response){                if(!success){                    this.fireEvent("loadexception", this, o, response);                    o.request.callback.call(o.request.scope, null, o.request.arg, false);                    return;                }                var result;                try {                    result = o.reader.readRecords(response);                    result.totalRecords=totalRecords;                }catch(e){                    this.fireEvent("loadexception", this, o, response, e);                    o.request.callback.call(o.request.scope, null, o.request.arg, false);                    return;                }                this.fireEvent("load", this, o, o.request.arg);                o.request.callback.call(o.request.scope, result, o.request.arg, true);            }        });            }-*/;        public abstract void load(int start, int limit, final JavaScriptObject o);        protected void loadResponse(JavaScriptObject o, boolean success, int totalRecords, String[][] data){        loadResponse(o, true, totalRecords,  JavaScriptObjectHelper.convertToJavaScriptArray(data));            }        protected native void loadResponse(JavaScriptObject o, boolean success, int totalRecords, JavaScriptObject response)/*-{        var m = this.@com.gwtext.client.core.JsObject::getJsObj()();        m.loadResponse(o, success, totalRecords, response);     }-*/;         static{        init();    }}You should subclass GWTProxy. Implementation of load method could look like this. Code:     public void load(int start, int limit, final JavaScriptObject o){        Server.handle(new GimmeMyFrickingData(start, limit), new AsyncCallback(){            public void onFailure(Throwable caught) {                loadResponse(o, false, 0, (JavaScriptObject)null);            }            public void onSuccess(Object result) {                MyFrickingData mfd = (MyFrickingData) result;                loadResponse(o, true, mfd.totalRecords,  mfd.data);            }});    }GWTProxy is designed to work with ArrayReader. Code: Store store = new Store(new MyGWTProxy(), new ArrayReader(recordDef), true); Back to top  500)this.width=500'>     500)this.width=500'> bleitner  Post subject: Re: How could I get remote data for paging grid in a GWT way? 500)this.width=500'>Posted: Tue Mar 04, 2008 9:27 pm  500)this.width=500'>Joined: Thu Feb 28, 2008 2:50 pmPosts: 10 Will this GWTProxy play nicely with a PagingToolbar? What about LoadMasks? These are the things I'm having issues with on a subclass of Store that doesn't use a DataProxy, instead manipulating the records manually. Back to top  500)this.width=500'>     500)this.width=500'> urban.novak  Post subject: Re: How could I get remote data for paging grid in a GWT way? 500)this.width=500'>Posted: Wed Mar 05, 2008 4:44 am  500)this.width=500'>Joined: Tue Feb 26, 2008 9:58 amPosts: 35 GWTProxy (just like any DataProxy) doesn't interact directly with Grid. It just handles data requests from Store, so it doesnt change behaviour of PagingToolbar or loadmasks. I've tested grid with PagingToolbar, loadmask and GWTProxy and it and it worked fine. bleitner wrote: Will this GWTProxy play nicely with a PagingToolbar? What about LoadMasks? These are the things I'm having issues with on a subclass of Store that doesn't use a DataProxy, instead manipulating the records manually. Back to top  500)this.width=500'>     500)this.width=500'> urban.novak  Post subject: Re: How could I get remote data for paging grid in a GWT way? 500)this.width=500'>Posted: Wed Mar 05, 2008 4:50 am  500)this.width=500'>Joined: Tue Feb 26, 2008 9:58 amPosts: 35 MyFrickingData can look like this ... Code:     public static class MyFrickingData{        public String[][] data;        public int totalRecords;    } dragos wrote: I apreciate verry much the ideea but coud you tell me what's the real type of mfd.data. How is my RPC data wrapped into mfd.data as i see tha here is of JavascriptObject type.QUOTE[ loadResponse(o, true, mfd.totalRecords, mfd.data); ]Thanks! Back to top  500)this.width=500'>     500)this.width=500'> urban.novak  Post subject: Re: How could I get remote data for paging grid in a GWT way? 500)this.width=500'>Posted: Wed Mar 05, 2008 5:16 am  500)this.width=500'>Joined: Tue Feb 26, 2008 9:58 amPosts: 35 Here is updated version of GWTProxy, that supports sorting. Code: package com.gwtext.client.data;import com.google.gwt.core.client.JavaScriptObject;import com.gwtext.client.util.JavaScriptObjectHelper;public abstract class GWTProxy extends DataProxy{        public GWTProxy(){        jsObj = create();    }    protected native JavaScriptObject create() /*-{        var o=new $wnd.Ext.ux.data.GWTProxy();        o.gwtmem=this;        return o;    }-*/;        private static native void init()/*-{        $wnd.Ext.namespace("Ext.ux");        $wnd.Ext.namespace("Ext.ux.data");        $wnd.Ext.ux.data.GWTProxy = function(){            $wnd.Ext.ux.data.GWTProxy.superclass.constructor.call(this);        };                        $wnd.Ext.extend($wnd.Ext.ux.data.GWTProxy, $wnd.Ext.data.DataProxy, {            load : function(params, reader, callback, scope, arg){                    var  o = {                        params : params || {},                        request: {                            callback : callback,                            scope : scope,                            arg : arg                        },                        reader: reader,                        callback : this.loadResponse,                        scope: this                    };                     this.gwtmem.@com.gwtext.client.data.GWTProxy::load(Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/String;Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)                    (params.start==undefined?null:params.start, params.limit==undefined?null:params.limit,params.sort==undefined?null:params.sort,params.dir==undefined?null:params.dir,o);               },            loadResponse : function(o, success, totalRecords, response){                if(!success){                    this.fireEvent("loadexception", this, o, response);                    o.request.callback.call(o.request.scope, null, o.request.arg, false);                    return;                }                var result;                try {                    result = o.reader.readRecords(response);                    result.totalRecords=totalRecords;                }catch(e){                    this.fireEvent("loadexception", this, o, response, e);                    o.request.callback.call(o.request.scope, null, o.request.arg, false);                    return;                }                this.fireEvent("load", this, o, o.request.arg);                o.request.callback.call(o.request.scope, result, o.request.arg, true);            }        });            }-*/;        public abstract void load(Integer start, Integer limit, String sort, String dir, final JavaScriptObject o);        protected void loadResponse(JavaScriptObject o, boolean success, int totalRecords, String[][] data){        loadResponse(o, true, totalRecords,  JavaScriptObjectHelper.convertToJavaScriptArray(data));            }        protected native void loadResponse(JavaScriptObject o, boolean success, int totalRecords, JavaScriptObject response)/*-{        var m = this.@com.gwtext.client.core.JsObject::getJsObj()();        m.loadResponse(o, success, totalRecords, response);     }-*/;         static{        init();    }} Back to top  500)this.width=500'>     500)this.width=500'> Seleuco  Post subject: Re: How could I get remote data for paging grid in a GWT way? 500)this.width=500'>Posted: Thu Mar 06, 2008 1:50 pm  500)this.width=500'>Joined: Fri Feb 29, 2008 2:25 pmPosts: 12 Thanks for the GWTProxy, but i have a problem with it...When i compile to javascript i get a exception in the IE... undefined/undefined in the GWT environment works OK...I have subclasing the GWTProxy: Code: public class GWTGridProxy extends GWTProxy {   public void load(Integer start, Integer limit, String sort, String dir, final JavaScriptObject o) {                   IEmployeesServiceRPCAsync service = this.getService();                service.getGridData((short)1,start, limit, sort, dir, new AsyncCallback(){      public void onFailure(Throwable caught) {          loadResponse(o, false, 0, (JavaScriptObject)null);          MessageBox.alert("Fail!"+caught.getMessage()+" "+caught.getCause());          caught.printStackTrace();        //EmployeeGridData mfd = new EmployeeGridData();      //mfd.totalRecords=1;      //mfd.data = new  String[][]{{"1","2","3","4"}};             //loadResponse(o, true, mfd.totalRecords,  mfd.data);                }      public void onSuccess(Object result) {          EmployeeGridData mfd = (EmployeeGridData) result;          loadResponse(o, true, mfd.totalRecords,  mfd.data);          MessageBox.alert("OK!");      }});                }       protected IEmployeesServiceRPCAsync getService(){               IEmployeesServiceRPCAsync employeesService =           (IEmployeesServiceRPCAsync) GWT.create(IEmployeesServiceRPC.class);                           ServiceDefTarget endpoint = (ServiceDefTarget)employeesService;        String moduleRelativeURL = GWT.getModuleBaseURL() + "employeesService";            endpoint.setServiceEntryPoint(moduleRelativeURL);                    return employeesService;       }}My data is: Code: public  class EmployeeGridData implements java.io.Serializable{   private static final long serialVersionUID = 1L;   public String[][] data;            public int totalRecords;}Thanks in advance! Back to top  500)this.width=500'>     500)this.width=500'> Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending  500)this.width=500'> 500)this.width=500'>  Page 1 of 4  [ 34 posts ]  Board index : GWT-Ext Forums : GWT-Ext 2.x DiscussionGo to page 1, 2, 3, 4  Next


阅读全文(2543) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.047 second(s), page refreshed 144817030 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号