PDA

View Full Version : Passing Params to directFn



tuxhero
22 May 2009, 12:13 AM
I was trying to pass params to my directFn function in Ext.data.DataStores but none of the way is working. By looking at source i found API Docs and source does not match. Can some one help me out.

My Source

new Ext.data.DirectStore({
storeId:'plugin-man',
paramsAsHash:false,
autoLoad:true,
directFn:Ext.ss.forge_configManager.read_details,
paramOrder:'interfaceMan_pluginDetails',
fields:['pluginName','pluginDescription','pluginPid','pluginModule','startup','startTime','stopTime','status']
})

ext-all-debug.js


Ext.data.DirectProxy = function(config){

if(typeof this.paramOrder == 'string'){
this.paramOrder = this.paramOrder.split(/[\s,|]/);
}
Ext.data.DirectProxy.superclass.constructor.call(this, config);
};

Ext.extend(Ext.data.DirectProxy, Ext.data.DataProxy, {

paramOrder: undefined,


paramsAsHash: true,


directFn : undefined,

// protected
doRequest : function(action, rs, params, reader, callback, scope, options) {
var args = [];

var directFn = this.api[action] || this.directFn;
switch (action) {
case Ext.data.Api.CREATE:
args.push(params[reader.meta.root]); // <-- create(Hash)
break;
case Ext.data.Api.READ:
if(this.paramOrder){
for(var i = 0, len = this.paramOrder.length; i < len; i++){
args.push(params[this.paramOrder[i]]);
}
}else if(this.paramsAsHash){
args.push(params);
}
break;
case Ext.data.Api.UPDATE:
args.push(params[reader.meta.idProperty]); // <-- save(Integer/Integer[], Hash/Hash[])
args.push(params[reader.meta.root]);
break;
case Ext.data.Api.DESTROY:
args.push(params[reader.meta.root]); // <-- destroy(Int/Int[])
break;
}
args.push(this.createCallback(action, reader, callback, scope, options));
directFn.apply(window, args);
},

// private
createCallback : function(action, reader, callback, scope, arg) {
return {
callback: (action == Ext.data.Api.READ) ? function(result, e){
if (!e.status) {
this.fireEvent(action+"exception", this, e, result);
callback.call(scope, null, arg, false);
return;
}
var records;
try {
records = reader.readRecords(result);
}
catch (ex) {
this.fireEvent("writeexception", this, action, e, result, ex);
callback.call(scope, null, arg, false);
return;
}
this.fireEvent("write", this, action, e, arg);
callback.call(scope, records, arg, true);
} : function(result, e){
if(!e.status){
this.fireEvent("writeexception", this, action, e);
callback.call(scope, null, e, false);
return;
}
this.fireEvent("write", this, action, result, e, arg);
callback.call(scope, result, e, true);
},
scope: this
}
}
});


Docs Source

/**
* @class Ext.data.DirectProxy
* @extends Ext.data.DataProxy
*/
Ext.data.DirectProxy = function(config){
Ext.apply(this, config);
if(typeof this.paramOrder == 'string'){
this.paramOrder = this.paramOrder.split(/[\s,|]/);
}
Ext.data.DirectProxy.superclass.constructor.call(this);
};

Ext.extend(Ext.data.DirectProxy, Ext.data.DataProxy, {

/**
* @cfg {Array/String} paramOrder Defaults to undefined. A list of params to be executed
* server side. Specify the params in the order in which they must be executed on the server-side
* as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
* comma, or pipe. For example,
* any of the following would be acceptable:


paramOrder: ['param1','param2','param3']
paramOrder: 'param1 param2 param3'
paramOrder: 'param1,param2,param3'
paramOrder: 'param1|param2|param'



*/
paramOrder: undefined,


/**
* @cfg {Boolean} paramsAsHash
* Send parameters as a collection of named arguments (defaults to true). Providing a
* {@link #paramOrder} nullifies this configuration.
*/
paramsAsHash: true,

// protected
doRequest : function(action, rs, params, reader, writer, cb, scope, options) {
var args = [];
var directFn = this.api[action];
switch (action) {
case 'save':
args.push(params[reader.meta.idProperty]); // <-- save(Integer/Integer[], Hash/Hash[])
args.push(params[writer.dataProperty]);
break;
case 'destroy':
args.push(params[writer.dataProperty]); // <-- destroy(Int/Int[])
break;
case 'create':
args.push(params[writer.dataProperty]); // <-- create(Hash)
break;
case 'load':
args.push(params); // <-- load(Hash)
break;
}
args.push(this.createCallback(action, reader, cb, scope, options));
directFn.apply(window, args);
},

// private
createCallback : function(action, reader, cb, scope, arg) {
return {
callback: (action == 'load') ? function(result, e){
if (!e.status) {
this.fireEvent(action+"exception", this, e, result);
cb.call(scope, null, arg, false);
return;
}
var records;
try {
records = reader.readRecords(result);
}
catch (ex) {
this.fireEvent(action+"exception", this, e, result, ex);
cb.call(scope, null, arg, false);
return;
}
this.fireEvent(action, this, e, arg);
cb.call(scope, records, arg, true);
} : function(result, e){
if(!e.status){
this.fireEvent(action+"exception", this, e);
cb.call(scope, null, e, false);
return;
}
this.fireEvent(action, this, result, e, arg);
cb.call(scope, result, e, true);
},
scope: this
}
}
});

ficeto
22 May 2009, 11:20 AM
in both cases it will not work.
here is what works:


var myStore = new Ext.data.DirectStore({
root:'data',
totalProperty:'rows',
idProperty:'id',
autoLoad:true,
remoteSort:true,
fields: fields,
baseParams:{start:0,limit:20,sort:'id',dir:'ASC'},
api:{
load: function(params, proxy){
//console.log(params);//{start:0,limit:20,sort:'id',dir:'ASC'}
MyDirectFunction.method(params,function(provider, response){
//process response
});
}
}
});
this is the only way i found to be able to pass arguments to a Direct function. It's actually one parameter that is an array of all parameters. (works great for me)

dj
25 May 2009, 6:12 AM
Ext.data.Store#baseParams / Ext.data.Store#setBaseParam works for me:


var myStore = new Ext.data.DirectStore({
root:'data',
totalProperty:'rows',
idProperty:'id',
autoLoad:true,
remoteSort:true,
fields: fields,
baseParams:{start:0,limit:20,sort:'id',dir:'ASC', any:'param', you:'want', goes:'here'},
directFn:Ext.ss.forge_configManager.read_details
});

or


var myStore = new Ext.data.DirectStore({
root:'data',
totalProperty:'rows',
idProperty:'id',
remoteSort:true,
fields: fields,
baseParams:{start:0,limit:20,sort:'id',dir:'ASC'},
directFn:Ext.ss.forge_configManager.read_details
});
myStore.setBaseParam('custom_param', 'value');
myStore.reload();


adding params to the load call works, too:


var myStore = new Ext.data.DirectStore({
root:'data',
totalProperty:'rows',
idProperty:'id',
remoteSort:true,
fields: fields,
directFn:Ext.ss.forge_configManager.read_details
});
myStore.setBaseParam('custom_param', 'value');
myStore.load({
params: {start:0,limit:20,sort:'id',dir:'ASC'}
});

dweller
29 Jul 2009, 12:34 AM
Ext.data.Store#baseParams / Ext.data.Store#setBaseParam works for me:


var myStore = new Ext.data.DirectStore({
root:'data',
totalProperty:'rows',
idProperty:'id',
autoLoad:true,
remoteSort:true,
fields: fields,
baseParams:{start:0,limit:20,sort:'id',dir:'ASC', any:'param', you:'want', goes:'here'},
directFn:Ext.ss.forge_configManager.read_details
});
or


var myStore = new Ext.data.DirectStore({
root:'data',
totalProperty:'rows',
idProperty:'id',
remoteSort:true,
fields: fields,
baseParams:{start:0,limit:20,sort:'id',dir:'ASC'},
directFn:Ext.ss.forge_configManager.read_details
});
myStore.setBaseParam('custom_param', 'value');
myStore.reload();
adding params to the load call works, too:


var myStore = new Ext.data.DirectStore({
root:'data',
totalProperty:'rows',
idProperty:'id',
remoteSort:true,
fields: fields,
directFn:Ext.ss.forge_configManager.read_details
});
myStore.setBaseParam('custom_param', 'value');
myStore.load({
params: {start:0,limit:20,sort:'id',dir:'ASC'}
});



can you tell me the server side code.I can't found method to receive parameter.
thanks

dj
1 Aug 2009, 2:22 AM
What server-side are you using? Which Ext.Direct library?

Basically the params are part of the data hash that gets sent to the server:


{"action":"TheAction","method":"TheMethod","data":[{"start":0,"limit":20,"sort":'id',"dir":'ASC', "any":'param', "you":'want', "goes":'here'}],"type":"rpc","tid":2}

dweller
2 Aug 2009, 4:36 PM
What server-side are you using? Which Ext.Direct library?

Basically the params are part of the data hash that gets sent to the server:


{"action":"TheAction","method":"TheMethod","data":[{"start":0,"limit":20,"sort":'id',"dir":'ASC', "any":'param', "you":'want', "goes":'here'}],"type":"rpc","tid":2}
we use DirectJNgine as server-side .
Now I get answer:DirectJNgine1.0 not support dynamic parameter.

thanks

dj
3 Aug 2009, 12:08 AM
Hi dweller,

this seems to be (a) a problem with your server-side library or (b) a misconfiguration of the server-side library. Any ways, http://extjs.com/forum/showthread.php?t=73027 is the right place to ask. Make sure that you include some more code of you problem or even an example and I'm sure they can help you out.

pagullo
3 Aug 2009, 10:43 PM
we use DirectJNgine as server-side .
Now I get answer:DirectJNgine1.0 not support dynamic parameter.

thanks

Hi.

Definitely, dynamic params can be handled by DirectJNgine. You need to use a feature of DirectJNgine 1.0 final (but not RC1, which I think is what you were using at the time), that allows you to handle requests by using a JSON handling method, which will receive a JsonArray with the request data.

In a dynamic parameters scenario, you need to handle the data at a lower level because there is no way DJN can know the right data types to instantiate if you ever receive a complex object as a dynamic parameter.

Take a look at the Handling JSON data directly chapter in the User's Guide for additional info.

If you have more questions about this issue, just post them in the main DirectJNgine thread (http://extjs.com/forum/showthread.php?t=73027), please.

Regards,

Pedro

waqar
14 Mar 2012, 6:00 AM
@dweller

Are you using ExtJs4 , if yes then does the DJN1.0 supports ExtJs 4 ?
is your problem solved, which technique did you finally used to get through for passing parameters to from Direct store to Java method.

please share ..




we use DirectJNgine as server-side .
Now I get answer:DirectJNgine1.0 not support dynamic parameter.

thanks