PDA

View Full Version : How to manually select an item (combobox)



Reghin
10 Jul 2009, 5:58 AM
I have a combobox bound to a store. This store is bound to a GWT-RPC service (via proxy) and works well.

What I need to do is once the data (list of BeanModelTag) returns from the server, manually set the combobox's selected item to the first bean in the list.

I've tried combobox.setValue as well combobox.select inside the loaderLoad event, but not working.

Is this event the right place I should put any setValue or select? If not, where?

fother
10 Jul 2009, 6:32 AM
Create your combo box and overwrite the method get and set


MyComboBox extends ComboBox


the behaviour of the combo box should be different.. but the gxt team.. dont change.. so its the soluction..

other way.. you can use memory proxy.. but its bad.. will store all data of your combobox..

sven
10 Jul 2009, 6:36 AM
Create your combo box and overwrite the method get and set


MyComboBox extends ComboBox


the behaviour of the combo box should be different.. but the gxt team.. dont change.. so its the soluction..

other way.. you can use memory proxy.. but its bad.. will store all data of your combobox..

This is wrong. Please reread the requirement of the opener.


The store gets first loaded on the first expand of the list. You could manually load the store and than you could listen to the loade vent and set the first value.

fother
10 Jul 2009, 6:44 AM
so.. try add a listener in a store when the data finished store and call the method select..

Reghin
10 Jul 2009, 7:54 AM
Adding a listener to the store solved the problem. =)



storeContrato = new ListStore<BeanModel>(loaderContrato);
storeContrato.addStoreListener(new StoreListener<BeanModel>() {
@Override
@SuppressWarnings("unchecked")
public void storeDataChanged(StoreEvent<BeanModel> se) {
super.storeDataChanged(se);
List<BeanModel> beans = (List<BeanModel>) se.getStore().getModels();
if (beans != null && beans.size() == 1) {
comboContrato.setValue(beans.get(0));
}
}
});


Thank you!!!

srinivas.itb
5 Jan 2011, 9:46 PM
I have a combo box in GXT wizard. Which has a proxy service & loader to retrieve the elements. How can i load the elements manually instead of loading by automatic ?

juanmav82
25 Jan 2012, 12:13 PM
This is wrong. Please reread the requirement of the opener.


The store gets first loaded on the first expand of the list. You could manually load the store and than you could listen to the loade vent and set the first value.

Can you explain how to manually load the store using a proxy service?

Thanks in advance

sven
25 Jan 2012, 12:38 PM
Can you explain how to manually load the store using a proxy service?

Thanks in advance

You can call the load method of the loader that you have bound to your store.

juanmav82
25 Jan 2012, 2:47 PM
Sven thanks for the fast reply, but still i cant make it work.

My code is the follow: ( I have been used Reghin's code)



final ComboBox combobox;
combobox = (ComboBox) this.itemModificacion.getItemByItemId(f.getName());
combobox.getStore().addStoreListener(new StoreListener<BeanModel>() {
@Override
@SuppressWarnings("unchecked")
public void storeDataChanged(StoreEvent<BeanModel> se) {
super.storeDataChanged(se);
List<BeanModel> beans = (List<BeanModel>) se.getStore().getModels();
if (beans != null && beans.size() == 1) {
combobox.setValue(beans.get(0));
}
}
});


When I click the combobox this fire the listener. But no one item is selected. Can you point me in right direction?

Thanks in advance

juanmav82
26 Jan 2012, 9:11 AM
I already solve it, I changed my code as follow.

Thanks!



Long fk = grid.getSelectionModel().getSelectedItem().get(f.getName());
combobox = (ComboBox) this.itemModificacion.getItemByItemId(f.getName());
List<BeanModel> beans = (List<BeanModel>) combobox.getStore().getModels();
if (beans != null) {
int i = 0;
Long auxfk;
do {
auxfk = (Long)beans.get(i).getProperties().get("id");
combobox.setValue(beans.get(i));
i++;
} while (auxfk != fk);
}



Sven thanks for the fast reply, but still i cant make it work.

My code is the follow: ( I have been used Reghin's code)



final ComboBox combobox;
combobox = (ComboBox) this.itemModificacion.getItemByItemId(f.getName());
combobox.getStore().addStoreListener(new StoreListener<BeanModel>() {
@Override
@SuppressWarnings("unchecked")
public void storeDataChanged(StoreEvent<BeanModel> se) {
super.storeDataChanged(se);
List<BeanModel> beans = (List<BeanModel>) se.getStore().getModels();
if (beans != null && beans.size() == 1) {
combobox.setValue(beans.get(0));
}
}
});


When I click the combobox this fire the listener. But no one item is selected. Can you point me in right direction?

Thanks in advance

i52ael
16 Jul 2013, 8:39 AM
ListStore arr=new ListStore();
ComboBox cbx = new ComboBox();
cmbxNewCombobox.setDisplayField("field");
cbx.setStore(arr);
ModelData m=new BaseModelData();
m.set("field","data1");
m.set("field","data2");
combo.add(m);
//select index 1
combo.setValue(arr.getAt(1));