Search code examples
javascriptyuidwr

Is there a plugin or extension that allows to use DWR remote calls as a YUI Data Source?


Is there a plugin or extension that allows to use DWR remote calls as a YUI Data Source?


Solution

  • There is no plugin to do that. DwrYuiDataSource currently supports remote methods of the form

    public ReturnType methodName(String query)
    

    But could easily be extended to take beforeArgs and afterArgs so that it supports

    public ReturnType methodName(Object beforeArg1, Object beforeArg2,
        String query, Object afterArg1, Object afterArg2)
    

    javascript: DwrYuiDataSource

    mypackage.DwrYuiDataSource = function(remoteMethod) {
        this.remoteMethod = remoteMethod;
        this._init();
    };
    
    mypackage.DwrYuiDataSource.prototype = new YAHOO.widget.DataSource();
    
    mypackage.DwrYuiDataSource.prototype.doQuery = function(oCallbackFn,
    sQuery, oParent) {
        var oSelf = this;
        this.remoteMethod(sQuery, function(aResults) {
            var resultObj = {};
            resultObj.query = decodeURIComponent(sQuery);
            resultObj.results = aResults;
            oSelf._addCacheElem(resultObj);      
            oSelf.getResultsEvent.fire(oSelf, oParent, sQuery, aResults);
            oCallbackFn(sQuery, aResults, oParent);
        });
    };