PDA

View Full Version : [Solved] HttpProxy & dynamic URL



brunod
2 Nov 2009, 2:02 PM
[using Ext 3.0]

Hello all,

I am playing with a bunch of auto-complete combos on a page (I have 3 of them) and a remote data store, using HttpProxy. My problem is I can't figure out how to properly set a dynamic URL as the url for HttpProxy. In short, does anyone know how can I construct a URL dynamically (in javascript) and set that before any request is done by the combo to the remote data store?


The reason is, my the combos are inter-dependent, e.g. the value in the first one affects the value in 2 others (and vice-versa), so assuming these parameters are numbered 1 to 3, I'd like a URL like this to be sent to the server by the Combo:



http://localhost...../someServerSide.jsp?p1=bla,p2=bla2,p3=bla3where bla, bla2 and bla3 are the values currently typed in each of the combos, and which obviously would change to whatever the value is currently in each of the combo.

What I've tried so far is:
- put some function like "url: generateUrl()" in the 'url' parameter of the proxy, but then that only gets calculated once and does not 'refresh'.
- put some anonymous function "url: function() { return generateUrl(); }" but then got a JS error.
- set an event listener to focus event so that the URL gets regenerated when user clicks insider either of the combos to edit them, here's a code snippet:


listeners: { 'focus': function() {
var url = generateUrl();
myProxy.setUrl(url, true);
}},
But then even that fails because in some cases it seems like this URL does not "stick" (for example when I type in a few words in either of the boxes, eventually the original URL (not the one set dynamically) shows up on the server for some odd reason.

What's the correct way to do this, if any?

brunod
4 Nov 2009, 8:16 AM
Ok, I wish there was a way to configure the ComboBox to use a dynamic URL (for example, be able to provide a function for the 'url' parameter of the HttpProxy which gets executed whenever a request is made). But anyway, I didn't find such a way and no one replied here, so I will post the work-around that I found. Basically, I just set the URL every time the combo does a query in the 'beforequery' event. Here's a snippet (myProxy is a HttpProxy instance, and 'getSearchAjaxUrl' my function to get the url) :



var combo = new Ext.form.ComboBox({
...
listeners: {
beforequery: function(qe){
var url = getSearchAjaxUrl();
myProxy.setUrl(url, true);
}
},
});