PDA

View Full Version : How to dynamically pass field value for RESTful URL?



locutusUT
9 Jul 2010, 1:54 PM
Hello,

I've used JsonStore plenty of times by passing in params to seed return results but how do you do this for a RESTful URL where part of the URL is the value for a query. For instance, in the following code, how can I pass the value that someone is typing in the combo box for the JsonStore that is used as a store for the combobox. Seems like chicken-and-egg problem. This code results in nothing being rendered because the url for the ScriptTagProxy is undefined because at startup it is not known yet.



Ext.onReady(function() {
var remoteJsonStore = new Ext.data.JsonStore({
root: 'user',
fields: [
{name: 'uid'},
{name: 'name'},
{name: 'email'},
{name: 'dept'}
],
restful: true,
proxy: new Ext.data.ScriptTagProxy( {
url: 'http://myldapserver/ldap-services/services/ldap/jsonp-getusers/' + combo.valueField
})
});
var combo = {
xtype: 'combo',
fieldLabel : 'Search:',
forceSelection : true,
displayField : 'name',
valueField : 'uid',
hiddenName : 'h_uid',
loadingText : 'Searching....',
minChars : 3,
triggerAction : 'name',
store : remoteJsonStore
};

new Ext.Window({
title : 'People Searcher',
height : 100,
layout : 'form',
labelWidth : 100,
bodyStyle : 'padding: 5px',
items : combo
}).show();
});


Any advice on how I can code this to wait for the results that are typed in to seed the RESTful URL?

TIA!

Condor
9 Jul 2010, 11:12 PM
1. You can't have restful actions with a ScriptTagProxy. A ScriptTagProxy can only do GET requests.
2. You will need to write a beforeload event that modifies the url, e.g.

listeners: {
beforeload: function(store, options){
var name = options.params.name;
delete options.params.name;
store.proxy.setApi('read', {
url: 'http://myldapserver/ldap-services/services/ldap/jsonp-getusers/' + name
});
}
}
3. triggerAction:'name' is invalid. You want:

triggerAction: 'query',
queryParam: 'name'

locutusUT
12 Jul 2010, 10:58 AM
Thanks Condor! Am I to understand that I should end of with the following:



Ext.onReady(function() {
var remoteJsonStore = new Ext.data.JsonStore({
root: 'user',
fields: [
{name: 'uid'},
{name: 'name'},
{name: 'email'},
{name: 'dept'}
],
proxy: new Ext.data.ScriptTagProxy(),
listeners: {
beforeload: function(store, options){
var name = options.params.name;
delete options.params.name;
store.proxy.setApi('read', {
url: 'http://myldapserver/ldap-services/services/ldap/jsonp-getusers/' + name
});
}
}
});
var combo = {
xtype: 'combo',
fieldLabel : 'Search:',
forceSelection : true,
displayField : 'name',
valueField : 'uid',
hiddenName : 'h_uid',
loadingText : 'Searching....',
minChars : 3,
typeAhead: 'true',
triggerAction: 'query',
queryParam: 'name',
store: remoteJsonStore
};

new Ext.Window({
title : 'People Searcher',
height : 100,
layout : 'form',
labelWidth : 100,
bodyStyle : 'padding: 5px',
items : combo
}).show();
});


The problem I'm having now is that options.params.name is null. How is it that I connect the the combobox entered data to the store?

Thanks.

Condor
12 Jul 2010, 11:33 AM
This should work. I don't see any errors.

Maybe I'm missing something. Try some debugging. What does options.params contain when you enter 3 characters in the combobox?

locutusUT
12 Jul 2010, 11:51 AM
Hmmm...when I set a breakpoint inside the listener, options.params = Object {}. Using Firebug I see no value inside the array.

locutusUT
13 Jul 2010, 9:33 AM
Ok, with some more testing, I see that options.params.name is actually set but only after I step through the beforeload listener, which seems to point to some sort of race condition or sequencing issue. I've tried to play with delays a bit to see if that would help but it consistently sets name after the beforeload. Am I missing something?

locutusUT
13 Jul 2010, 10:41 AM
Well for what's it worth, setting name = this.baseParams.name retrieved the value and allowed me to set the RESTful URL.

tusharrungta1987
16 Jan 2017, 8:20 AM
@locutusUT How are you parsing the http query of LDAP on the server ? Are you parsing it into VBScript or breaking the string ? Can you give some code example ?