`
牧羊人
  • 浏览: 210760 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ext3.0 dwrproxy 兼容2.x dwrproxy用法

阅读更多
经测试 可以用,并且做了修改可以兼容以前的代码格式

Ext.namespace("Ext.ux.data"); 
/** * @class Ext.ux.data.DwrProxy 
 * @extends Ext.data.DataProxy
 * @author loeppky 
 * An implementation of Ext.data.DataProxy that uses DWR to make a remote call. 
 * Not all of Ext.data.DataProxy's configuration options make sense for Ext.ux.data.DwrProxy. 
 * The following constructor sample code contains all the available options that can be set: 
 * <code><pre> 
 * new Ext.ux.data.DwrProxy({ 
 *   // Defined by Ext.data.DataProxy 
 *   api : { 
 *     read : DwrInterface.interfaceMethodName 
 *   }, 
 *   // Defined by Ext.Observable 
 *   listeners: { 
 *     'beforeload': function(dataProxy, params) { 
 *       // DwrProxy knows to pull parameters for the Dwr call from params[dataProxy.loadArgsKey]. 
 *       params[dataProxy.loadArgsKey] = [ 
 *         // arg1 for DwrInterface.interfaceMethodName 
 *         // arg2 for DwrInterface.interfaceMethodName 
 *         // etc... 
 *       ]; 
 *     } 
 *   }, 
 *   // Defined by Ext.ux.data.DwrProxy 
 *   loadArgsKey : 'newLoadArgsKey' // This configuration option should almost never need to be set 
 * }); 
 * </pre></code> 
 * Note that currently only the "read" operation is supported.  Support for the rest of the CRUD options will be added soon.    
 * @constructor 
 * @param {Object} config A configuration object where the following can be set: 
 * - api: as defined in {@link Ext.data.HttpProxy#api}.  This is where the DWR function for a given CRUD operation is specified.
 * Note: only "read" is currently supported. 
 * - listeners: as defined in {@link Ext.Observable#listeners} 
 * - loadArgsKey: as defined in {@link Ext.ux.data.DwrProxy#loadArgsKey}
 */
 Ext.ux.data.DWRProxy = function(config) {  
	// Set loadArgsKey if its defined. 
	 // We do this manually since Ext.data.DataProxy doesn't call Ext.apply with the config object.  
	 if (config && config.loadArgsKey) {
	 	    this.loadArgsKey = config.loadArgsKey;
	 }
          //兼容以前2.x的使用格式
          if(config && config.dwrFunction){
	 	    config.api={read:config.dwrFunction};
	 } 
	 Ext.ux.data.DWRProxy.superclass.constructor.call(this, config);
};
Ext.extend(Ext.ux.data.DWRProxy, Ext.data.DataProxy, {
   /**
   * @cfg {String} loadArgsKey Defines where in the params object passed to the load method   
   * that this class should look for arguments to pass to the "dwrFunction".   
   * The order of arguments passed to a DWR function matters.   
   * Must be set before calling load.   
   * See the explanation of the "params" parameter for the load function for further explanation.   
   */
   loadArgsKey: 'dwrFunctionArgs',
   /**   
   * DwrProxy implementation of DataProxy#doRequest.   
   * This implementation attempts to mirror HttpProxy#doRequest as much as possible.   
   * Requests are done using configured "DWR function" for the provided "action".   
   * In the "read" case, the response data object is read into a block of Ext.data.Records using the passed {@link Ext.data.DataReader},   
   * and the records are then passed using to the provided callback.   
   * @param {String} action The crud action type (create, read, update, destroy).  Note: only "read" is currently supported.   
   * @param {Ext.data.Record/Ext.data.Record[]} records If action is "read", records will be null.   
   * @param {Object} params An object containing properties which are to be used as parameters for the request to the remote server.   
   * Params is an Object, but the "DWR function" needs to be called with arguments in order.   
   * To ensure that one's arguments are passed to their DWR function correctly, a user must either:   
   * 1. call or know that the execute method was called explictly where the "params" argument's properties were added in the order expected by DWR OR   
   * 2. listen to the "beforeload" and/or "beforewrite" events and add a property to params defined by "loadArgsKey" that is an array of the arguments to pass on to DWR.   
   * If there is no property as defined by "loadArgsKey" within "params", then the whole "params" object will be used as the "loadArgs".   
   * If there is a property as defined by "loadArgsKey" within "params", then this property will be used as the "loagArgs".   
   * The "loadArgs" are iterated over to build up the list of arguments to pass to the "DWR function".   
   * @param {Ext.data.DataReader} reader The Reader object which converts the data object into a block of Ext.data.Records.   
   * @param {Function} callback A function to be called after the request.   
   * The callback is passed the following arguments:<ul>   
   * <li>records: Ext.data.Record[] The block of Ext.data.Records handled by the request.</li>   
   * <li>params: The params object passed to this doRequest method</li>   
   * <li>success: Boolean success indicator</li>   
   * </ul>   
   * @param {Object} scope The scope in which to call the callback.   
   * @param {Object} options An optional argument which is passed to the callback as its second parameter.   
   * @private   
   */
   doRequest : function(action, records, params, reader, callback, callbackScope, options) {
   	    var dataProxy = this;
   	    var loadArgs = params[this.loadArgsKey] || params;
   	    // the Array or Object to build up the "dwrFunctionArgs"
   	    var dwrFunctionArgs = [];
   	    // the arguments that will be passed to the dwrFunction
   	    if (loadArgs instanceof Array) {
   	    // Note: can't do a foreach loop over arrays because Ext added the "remove" method to Array's prototype.
   	    // This "remove" method gets added as an argument unless we explictly use numeric indexes.
   	        for (var i = 0; i < loadArgs.length; i++) {        
   	        	dwrFunctionArgs.push(loadArgs[i]);      
   	        }
   	     } else { 
   	     	// loadArgs should be an Object      
   	     	for (var loadArgName in loadArgs) {        
   	     		dwrFunctionArgs.push(loadArgs[loadArgName]);      
   	     	}    
   	    }    
   	    dwrFunctionArgs.push(this.createCallback(action, params, reader, callback, callbackScope, options));    
   	    this.api.read.apply(Object, dwrFunctionArgs); // the scope for calling the dwrFunction doesn't matter, so we simply set it to Object.  
   	    },
   	/**   
   	* Helper method for doRequest which returns a callback function for a DWR request.   
   	* The returned callback function in turn invokes the provided callback function.   
   	* This mirrors HttpProxy#createCallsback.   
   	* DWR is unique though in that it allows one to define a callback function for success and callback function for an exception.   
   	* This exceptionHandler callback parallels Ext's "remote exception" case.   
   	* This method thus returns two callback functions groupded as a single object that can be appended to the DWR function arguments as required by DWR.   
   	* @param {String} action See doRequest#action.   
   	* @param {Ext.data.Record/Ext.data.Record[]} records See doRequest#records.   
   	* @param {Object} params See doRequest#params.   
   	* @param {Ext.data.DataReader} reader See doRequest#reader.   
   	* @param {Function} callback See doRequest#callback.   
   	* @param {Object} scope See doRequest#scope.   
   	* @param {Object} options See doRequest#options.   
   	* @private   
   	*/
   	
   	 createCallback : function(action, params, reader, callback, callbackScope, options) {
   	 	    return {      
	   	 	    	callback: function(response){        
	   	 	    		if (action === Ext.data.Api.actions.read) {          
	   	 	    			this.onRead(action, params, reader, callback, callbackScope, options, response);        
	   	 	    		} else {          
	   	 	    			this.onWrite();        
	   	 	    		}      
	   	 	    	}.createDelegate(this),      
	   	 	    	exceptionHandler : function(message, exception) {        
		   	 	    		if (action === Ext.data.Api.actions.read) {          
		   	 	    			// @deprecated: Fire loadexception for backwards compatibility.          
		   	 	    			// The event is supposed to pass the response, but since DWR doesn't provide that to us, we pass the message.          
		   	 	    			this.fireEvent("loadexception", this, params, message, exception);        
		   	 	    		}        
		   	 	    		// The event is supposed to pass the response, but since DWR doesn't provide that to us, we pass the message.        
		   	 	    		this.fireEvent("exception", this, 'remote', action, params, message, exception);        
		   	 	    		  callback.call(callbackScope, null, options, false);      
		   	 	    }.createDelegate(this)   
   	 	    };  
   	 },
   	 /**   
   	 * Helper method for createCallback for handling the read action.   
   	 * After creating records from the provided response, it calls the provided callback function.   
   	 * This mirrors HttpProxy#onRead.   
   	 * @param {String} action See doRequest#action.   
   	 * @param {Ext.data.Record/Ext.data.Record[]} records See doRequest#records.   
   	 * @param {Object} params See doRequest#params.   
   	 * @param {Ext.data.DataReader} reader See doRequest#reader.   
   	 * @param {Function} callback See doRequest#callback.   
   	 * @param {Object} scope See doRequest#scope.   
   	 * @param {Object} options See doRequest#options.   
   	 * @param {Object} response The response from the DWR call.  This should be an Object which can be converted to Ext.data.Records.   
   	 * @private   
   	 */
   	 onRead : function(action, params, reader, callback, callbackScope, options, response) {    
	   	 	  var records;    
	   	 	  try {      
	   	 	  	// Call readRecords verses read because read will attempt to decode the JSON,      
	   	 	  	// but as this point DWR has already decoded the JSON.      
	   	 	  	records = reader.readRecords(response);    
	   	 	  } catch(e) {      
	   	 	  	// @deprecated: Fire loadexception for backwards compatibility.      
	   	 	  	this.fireEvent("loadexception", this, params, response, e);      t
	   	 	  	his.fireEvent('exception', this, 'response', action, params, response, e);      
	   	 	  	callback.call(callbackScope, null, options, false);      
	   	 	  	return;    
	   	 	  }    
	   	 	  this.fireEvent("load", this, params, options);    
	   	 	  callback.call(callbackScope, records, options, true);  
   	 },
   	 /**   
   	 * Helper method for createCallback for handling the create, update, and delete actions.   
   	 * This mirrors HttpProxy#onWrite   
   	 * TODO: implement   
   	 * @private   
   	 */
   	 onWrite : function() {    
   	 	    throw new Exception('create, update, and delete actions are not implemented yet.')  
   	 }
});
2
1
分享到:
评论
1 楼 liluyang726 2010-06-12  
这个如何使用呢。2.x上的使用方式是不行的了。贴个例子

相关推荐

    ext js配合dwr在java中的用法

    dwrproxy.js 博文链接:https://cicada-it.iteye.com/blog/102949

    ext中dwrproxy与json处理数据技术

    ExtJs中使用dwrproxy,和json来处理从数据库里查询出来的数据 其中dwrproxy还支持分页(分页功能没做),将war包下载下来后,直接放在tomcat里,然后启动tomcat就可以了 数据库方面,该项目里用的是mysql,数据文件在...

    Ext的DWRProxy应用事例

    NULL 博文链接:https://clq9761.iteye.com/blog/1001863

    Ext深入浅出 数据传输

    11.17.2 扩展String......................... 306 11.17.3 扩展Function.................... 306 11.17.4 扩展Number......................... 308 11.17.5 扩展Array........................... 308 11.18 Ext....

    DWRProxy.js,DWRTreeLoader.js,PagingDWRProxy.js

    用EXT和DWR结合起来做工程时,在数据传输时会有点麻烦,这里提供的3个JS文件分别实现了DWR的数据代理,分页查询处理,动态树加载。并且实现了Ext.data.DWRArrayReader Ext.data.DWRXmlReader Ext.data....

    Ext扩展dwrproxy

    Ext扩展dwrproxyExt扩展dwrproxyExt扩展dwrproxyExt扩展dwrproxyExt扩展dwrproxyExt扩展dwrproxyExt扩展dwrproxyExt扩展dwrproxyExt扩展dwrproxy

    dwrproxy.js

    看到大家在讨论dwrproxy,这是本人修改后的.

    EXTJS 3 整合DWR (DWRProxy、DWRTreeLoader、DWRGridProxy )

    ExtJs3 DWR扩展 DWRProxy、DWRTreeLoader、DWRGridProxy,经过EXT3.0版本测试! 通过DWR向Ext提供数据!非常棒的扩展!

    dwrproxy.js,DWRTreeLoader.js,PagingDWRProxy.js

    Ext中结合dwr要用到的几个.js文件,下载后解压导入web工程中,

    dwrProxy.js

    dwrProxy.js

    精通JS脚本之ExtJS框架.part2.rar

    6.3 元素常见的使用方法 6.3.1 常见的“显示/隐藏”方法 6.3.2 常见的“内容控制”方法 6.3.3 常见的“操控DOM”方法 6.3.4 常见的“尺寸大小/定位”方法 6.3.5 常见的“特效动画”方法 6.3.6 DomHelper简介 ...

    EXT2.0中文教程

    D.2. 感谢[吧啦吧啦286556983]的大力支持 D.3. 感谢[游戏人生395181055]的大力支持 D.4. 感谢[綄帥77793603]的大力支持 D.5. 感谢[葡萄5793699]的大力支持 D.6. 感谢[天外小人442540141]的大力支持 D.7. 感谢[我想我...

    EXT教程EXT用大量的实例演示Ext实例

    D.2. 感谢[吧啦吧啦286556983]的大力支持 D.3. 感谢[游戏人生395181055]的大力支持 D.4. 感谢[綄帥77793603]的大力支持 D.5. 感谢[葡萄5793699]的大力支持 D.6. 感谢[天外小人442540141]的大力支持 D.7. 感谢...

    精通JS脚本之ExtJS框架.part1.rar

    6.3 元素常见的使用方法 6.3.1 常见的“显示/隐藏”方法 6.3.2 常见的“内容控制”方法 6.3.3 常见的“操控DOM”方法 6.3.4 常见的“尺寸大小/定位”方法 6.3.5 常见的“特效动画”方法 6.3.6 DomHelper简介 ...

    Ext 开发指南 学习资料

    A.2. 怎么查看ext2里的api文档 A.3. 如何在页面中引用ext A.3.1. 顺便说说常见的Ext is not defined错误 A.4. 想把弹出对话框单独拿出来用的看这里 A.5. 想把日期选择框单独拿出来用的看这里 A.6. 听说有人现在还...

    可用的dwrproxy.js,参考我的文章EXT+DWR分页

    EXT+DWR分页 ,前人基础修改,绝对能用 有问题的大家相互交流, 具体使用请参考我的文章EXT+DWR分页

    ExtJs DWR扩展 DWRProxy、DWRTreeLoader、DWRGridProxy

    ExtJs DWR扩展 DWRProxy、DWRTreeLoader、DWRGridProxy,经过EXT3.0版本测试! 通过DWR向Ext提供数据!非常棒的扩展!

    DWRProxy的运用实例,Ext,Dwr,Spring的完美结合

    是Ext+Dwr+Spring的完美结合。 表格中的数据是通过DWRProxy加载共分3中形式,用以下3中解析器来解析的: DWRJsonReader DWRArrayReader DWRXmlReader 数据完全由JAVA方法返回,由DWR动态调用,利用了Spring作为Bean...

    DwrProxy.js

    EXT2未加入对DWR的支持,此文件是对其的扩展进而实现DWR的支持

    Ext.data专题

    Ext.data 在命名空间中定义了一系列store、reader 和proxy。Grid 和ComboxBox 都是以Ext.data 为 媒介获取数据的,它包含异步加载、类型转换...DWRProxy 就实现了自身的proxy 和reader,让EXT 可以直接从DWR 获得数据。

Global site tag (gtag.js) - Google Analytics