PDA

View Full Version : passing params to DWRPRoxy



s.kerroumi
4 Jan 2008, 5:31 AM
hello,

I'm newbie in ExtJs so i need some informations...

i have a Jsp displaying a list of customers

i call my back-end with combo extJs+dwr via DWRPRoxy here is my implementation :



Ext.data.DWRProxy = function (f) {
Ext.data.DWRProxy.superclass.constructor.call(this);
this.func = f;
};

Ext.extend(Ext.data.DWRProxy, Ext.data.DataProxy, {
load : function(params, reader, callback, scope, arg) {
document.dwr = {params:params, reader:reader, callback:callback, scope:scope, arg:arg};
this.func.call(this, arg, {
callback: this.loadResponse,
exceptionHandler: this.failure,
});
},

loadResponse : function(response) {
var dwr = document.dwr;
delete document.dwr;
var result;
try {
result = dwr.reader.read(response);
}catch(e){
this.fireEvent("loadexception", this, o, response, e);
dwr.callback.call(dwr.scope, null, dwr.arg, false);
return;
}
dwr.callback.call(dwr.scope, result, dwr.arg, true);
},

failure : function(o, success, response) {
console.log("Failed"); // Not finished yet but should probably just call a failure callback
},

update : function(params, records){

}
});



i have a filter formular on these customers to, with several field.
i map those fields by creating a Javascript Object :


var filterClients = {pagename:null,number_value:null,name_value:null,location_id_value:null,parentCode_value:null,hideAll_value:null,country_id_value:null,exclusiveOnly_value:null};

i populate this object by this way :

dwr.util.getValues(filterClients);

so it fills corresponding values. it works fine.

On my server side, i have a method :


public Object[] loadCustomers(final FilterClients filter)

loadCustomers wait for a filter parameter of type FilterClients

my dwr.xml declare this object so it can be marshalled by DWR :

<convert converter="bean" match="com.clientssettings.filter.dwr.impl.FilterClients"/>

my question is : How the hell can i pass this filterClients Javascript Object properly with DWRProxy???????

s.kerroumi
4 Jan 2008, 6:26 AM
:D

i 've no reply okay :D

no problem cause i managed to solve my problem here is my solution if somebody is interested (i doubt) :

dwrproxy.js :



/**
* DWR proxy for the store
*/



Ext.data.DWRProxy = function(dwrCall, args){
Ext.data.DWRProxy.superclass.constructor.call(this );
this.dwrCall = dwrCall;
this.args = args;
};

Ext.extend(Ext.data.DWRProxy, Ext.data.DataProxy, {
load : function(params, reader, callback, scope, arg) {
if(this.fireEvent("beforeload", this, params) !== false) {
var delegate = this.loadResponse.createDelegate(this, [reader, callback, scope, arg], 1);
var callParams = new Array();
if(this.args && (this.args.length > 0))
callParams = this.args.slice();
callParams.push(delegate);
this.dwrCall.apply(this, callParams);
} else {
callback.call(scope || this, null, arg, false);
}
},

loadResponse : function(response, reader, callback, scope, arg) {
var result;
try {
result = reader.read(response);
} catch(e) {
this.fireEvent("loadexception", this, null, response, e);
callback.call(scope, null, arg, false);
return;
}
callback.call(scope, result, arg, true);
},

update : function(dataSet){},

updateResponse : function(dataSet)
{}
});

Ext.data.ObjectReader = function(meta, recordType){
Ext.data.ObjectReader.superclass.constructor.call(this, meta, recordType);
};
Ext.extend(Ext.data.ObjectReader, Ext.data.DataReader, {
read : function(response){
var sid = this.meta ? this.meta.id : null;
var recordType = this.recordType, fields = recordType.prototype.fields;
var records = [];
var root = response;
for(var i = 0; i < root.length; i++){
var obj = root[i];
var values = {};
var id = obj[sid];

for(var j = 0, jlen = fields.length; j < jlen; j++){
var f = fields.items[j];
var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : f.name;

var v = obj[k] !== undefined ? obj[k] : f.defaultValue;
v = f.convert(v);
values[f.name] = v;

}
var record = new recordType(values, id);
records[records.length] = record;
}
return {
records : records,
totalRecords : records.length
};
}
});


here is the way i populate my DataStore :


var ds = new Ext.data.Store({
proxy: new Ext.data.DWRProxy(CustomerUtil.loadCustomers,[filterClients]),
reader: new Ext.data.ObjectReader({id:'id'}, [
{name:'name',mapping:'name'},
{name:'code',mapping:'number'},
{name:'location',mapping:'location.label'},
{name:'parentCode',mapping:'parentCode'},
{name:'country',mapping:'country.label'}
])
});

var myDS=ds.load();