View Full Version : Ext.data.HttpProxy URL Help
MoShAn480
3 May 2007, 4:13 PM
Hi,
I am creating an auto complete field. I have some parameters whihc need to get updated in the Ext.data.HttpProxy url. How can i go about doing this? It seems once the url is set, it cannot be updated. If there is another way to attach parameters to the request url, then would also help.
Thanks in advance.
jsakalos
3 May 2007, 4:20 PM
Look at documentations of request method of Ext.data.Connection.
MoShAn480
3 May 2007, 4:25 PM
I think i may be blind, but i do not see it on this site:http://www.yui-ext.com/deploy/yui-ext/docs/
MoShAn480
3 May 2007, 4:27 PM
oops sorry wrong site, found it...thanks.
jsakalos
3 May 2007, 4:27 PM
http://extjs.com/deploy/ext/docs/output/Ext.data.Connection.html (http://extjs.com/forum/../deploy/ext/docs/output/Ext.data.Connection.html)
MoShAn480
3 May 2007, 4:33 PM
I am not seeing how this would be connected. Here is the code i working with:
var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: ajaxUrl + "?requestType=findAgentList&namePattern=" + namePattern + "&sessionId=" + _currentSessionId
}),
reader: new Ext.data.XmlReader({
root: 'topics',
totalProperty: 'totalCount',
id: 'post_id'
}, [
{name: 'title', mapping: 'topic_title'},
{name: 'topicId', mapping: 'topic_id'},
{name: 'author', mapping: 'author'},
{name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'},
{name: 'excerpt', mapping: 'post_text'}
])
});
// Custom rendering Template
var resultTpl = new Ext.Template(
'<div class="search-item">',
'<h3><span><br />{firstName}</span></h3>',
'{excerpt}',
'</div>'
);
var search = new Ext.form.ComboBox({
store: ds,
displayField:'title',
typeAhead: false,
loadingText: 'Searching...',
width: 250,
//pageSize:10,
hideTrigger:true,
tpl: resultTpl,
onSelect: function(record){ // override default onSelect to do redirect
alert('record');
}
});
As you can see, the parameters in the URL can change. When i try to get a reference to the proxy using:
ds.proxy = new Ext.data.HttpProxy({
url: proxyUrl
});
it does not work either. Thanks.
jsakalos
3 May 2007, 4:36 PM
Use firebug to see what you really send to server and what server sends back.
MoShAn480
3 May 2007, 4:41 PM
I can see what i am sending to the server in FireBug, and it is hitting the server fine. My URL needs to change by adding parameters in order to get the results i need. The HttpProxy will not let me update the url. I have tried making a global url string whihc changes, but that does not work either...
jsakalos
3 May 2007, 4:46 PM
Look in doc again. There is object params. It is place where you place your params.
tryanDLS
3 May 2007, 4:47 PM
Why are you trying to change the url - If you're building dynamic querystrings, they should be passed via the store's params object. This is no different than passing parms to the store for grid loading/paging.
MoShAn480
3 May 2007, 4:57 PM
I got this working by using the following on the datastore:
function updateHttpProxy (){
namePattern = document.getElementById('agentSearch').value;
proxyUrl = ajaxUrl + "?requestType=findAgentList&namePattern=" + namePattern + "&sessionId=" + _currentSessionId;
ds.proxy = new Ext.data.HttpProxy({
url: proxyUrl
});
}
var ds = new Ext.data.Store({
beforeload:function (){alert('test');},
proxy: new Ext.data.HttpProxy({
url: ajaxUrl + "?requestType=findAgentList&namePattern=" + namePattern + "&sessionId=" + _currentSessionId
}),
reader: new Ext.data.XmlReader({
root: 'list',
totalProperty: 'totalCount',
id: 'post_id'
}, [
{name: 'title', mapping: 'topic_title'},
{name: 'topicId', mapping: 'topic_id'},
{name: 'author', mapping: 'author'},
{name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'},
{name: 'excerpt', mapping: 'post_text'}
])
});
ds.on("beforeload", updateHttpProxy);
The application requires that i send additonal parameters to the server so that i can get the proper list back.
Thanks for your help, you pointed me in the right direction.
jsakalos
3 May 2007, 5:03 PM
Put your params to ds.baseParams object like this:
ds.baseParams = {
field1:'value1'
, field2:'value2'
... etc
}
then you can remove beforeload handler.
MoShAn480
4 May 2007, 8:45 AM
cool, thanks again for your help.
jsakalos
4 May 2007, 8:52 AM
You're welcome.
I'm glad I helped.
MoShAn480
9 May 2007, 1:49 PM
Hi,
is this how you are suggesting I update the parameter:
ds.baseParams = {requestType: 'findAgentList', sessionId: _currentSessionId, namePattern: namePattern};
I place the above code inside a funtion whihc i attach to the Sote like below:
var ds = new Ext.data.Store({
baseParams: {requestType: 'findAgentList'},
proxy: new Ext.data.HttpProxy({
url: ajaxUrl
}),
reader: new Ext.data.XmlReader({
record: 'person'
}, [
{name: 'name', mapping: 'name'},
{name: 'id', mapping: 'id'}
])
});
ds.on("beforeload", updateHttpProxy);
this works great except that the "queryParam" from the comboBox seems to get lost.
MoShAn480
9 May 2007, 1:51 PM
here is the updateHttpProxy code:
function updateHttpProxy (){
ds.baseParams = {requestType: 'findAgentList', sessionId: _currentSessionId, namePattern: namePattern};
}
jsakalos
9 May 2007, 2:02 PM
Not exactly:
ds.baseParams: { ... }; // everything what you want to save with each request
...
...
ds.load({params:{... everything what is this one load specific - see example in next line ...}};
ds.load({params:{start:0, limit:25, filter:'nebr'}};
and now you can remove beforeload listener.
MoShAn480
9 May 2007, 2:23 PM
In my application the sessionId parameter can change very often. It is a chat application, so the user switches chat sessions when he clicks the specific chat tab. When this happens, a global _currentSessionId variable gets changed. When user submit data to the server to auto-complete, that parameter needs to get updated. All previous methods seem to only set the parameter once.
So it seems that there is no way but to do this with beforeload handler.
jsakalos
9 May 2007, 2:32 PM
Maybe I don't grasp it fully ...:-|
Is the sessionId known at the time user clicks submit? If so put it to load's params. That is main purpose of passing params as arguments to load.
e.g.:
var sessionId = xxx; // global session Id
....
user switches tab => sessionId changed
....
ds.load({params:{sessionId:sessionId}});
MoShAn480
9 May 2007, 2:48 PM
I see what you are saying now. But a call to load() pulls data from the server though. How can i tie this into the combobox autocomplete functionality ? I would like to set the load parameters before the autocomplete calls load to pull the data?
Sorry in case i am frustrating you, but i am not seeing how this can work since anytime load is called, the server is queried for data. One of the parameters which i am also sending is coming from the textfield which is an auto complete combobox.
Thanks for all your help
jsakalos
9 May 2007, 2:54 PM
Maybe I am missing the goal you want to accomplish ;)
You can set combo's mode:'local'. In that case the data store load is totally under your control and combo doesn't get loaded on user actions.
Once you have data complete you put them to params and load store from script.
Or, am I on a totally wrong track?
MoShAn480
9 May 2007, 3:02 PM
I see your point. So i guess there is a trade off here between loading it manually and letting the ComboBox automatically load the data. If i do it manually, it seems load() function works great when passing dynamic parameters other than the query string.
This makes alot of sense now. Thanks for all your help.
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.