PDA

View Full Version : Help, Need to "select" An Item IN A Combo



chalu
18 Aug 2010, 11:58 PM
I am trying to programmatically load a combo and then select a particular item, so far it's not working, here is what I've done :


// progSelector is the combo, Programme is the model (BeanModel) bound to it.
// So, programme is an object of type Programme, and beanModel is the model selection from a Grid
....
programme = (Programme) beanModel.getBean();
final ListLoader<? extends ListLoadResult<BeanModel>> loader = progSelector.getStore().getLoader();
LoadListener listener = new LoadListener(){
@Override
public void loaderLoad(LoadEvent le) {
super.loaderLoad(le);
progSelector.select(beanModel);
loader.removeLoadListener(this);
}
};
loader.addLoadListener(listener);
loader.load();

I want to load the list of "Programmes" and then select a particular one (represented by beanModel), from firebug I can see that the store is loaded but the but:

The "result" item is shown as "selected" in the combo
when the combo's drop-down button is clicked it loads the combo again inspite of the first load ??


I'll appreciate your suggestions please.

chalu
26 May 2011, 4:47 AM
Ok I revisited this and decided to try something else :


progSelector.select(beanModel);

progSelector is the Combo configured to load "Programme" from the server, its store has been loaded in the onRender() method of the container where the combo is placed, so by the time the above code is called its store has successfully loaded. The beanModel object is a BeanModel of the "Programme" we want to select, gotten from another context (a Grid). This however throws a null pointer exception from the call to the select() method above, which is triggered from this line within the select(BeanModel) method of ComboBox.java:


fly(listView.getElement(index)).scrollIntoView(listView.getElement(), false);

Am sure the problem is the scrollIntoView() call, remember we are trying to make the combo show up with one of its items already selected, not with the "trigger" button.

So I tried even further with :


progSelector.getView().getSelectionModel().select(beanModel, false)

since that is basically what my initial select() call is doing, this prevents the error but it does not solve the problem, the beanModel is not selected!

So my question again is how do I select an item inside a combo within code, so that that option / item shows within the combo's text field the same way it does if I had clicked on the "trigger" button to make the selection. Any hints please.