PDA

View Full Version : Need help with setting parameter for comboBox load



catacaustic
13 May 2009, 5:37 PM
I'm trying to set up a ComboBox that loads it's list depending on the value of a second ComboBox. The first ComboBox is no problem, but I can't figure out how to set up the loader of the dependent ComboBox to send the value that I need back to the server.

I've implemented this as a new class extending ComboBox so the store, loader and these listeners are all implemented in the main constructor.

I've tried both of these listeners to see if I can get it working:

Attempt 1...

loader.addLoadListener (new LoadListener () {
public void loaderBeforeLoad (LoadEvent le) {
BaseListLoadConfig config = new BaseListLoadConfig ();
Map params = config.getParams ();
params.put("id", server_id);

loader.useLoadConfig (config);
} // beforeLoad ()
});

Attempt 2...

addListener (Events.BeforeQuery, new Listener<FieldEvent> () {
public void handleEvent(FieldEvent be) {
BaseListLoadConfig config = new BaseListLoadConfig ();
Map params = config.getParams ();
params.put("id", server_id);

config.setParams (params);

loader.useLoadConfig (config);
} // handleEvent ()
});

Both of these set the value correctly in the loaders config, but when the loader loads, it doesn't send this value.

Is this how it should be done, or is there another method of sending parameters back from the loader?

catacaustic
14 May 2009, 3:36 PM
I have found a way to do this, but it feels "dirty"... really not like it should be done this way at all, but so far there's no other way that I can see to do it.

To send the extra parameters back, you need to have the store NOT associated with the loader (which seems like a damned stupid idea, seeing as how that's what it's meant to do...). Then set a listener on the loader so that when it loads you can process the result yourself (isn't that supposed to be part of the loader/store relationship?), clear the store then add your own values to it.

As I said, even though this works, it does seem like it's one of the most idiotic ideas around. Is all this extra processing REALLY Required just to send a single parameter back when you want to load a store for a ComboBox??

I do really hope that there's a better way out there to do it, but until someone tells me(us), I guess we'll be forced to put up with this hack to make what should be a simple job into something a lot more cumbersome.