PDA

View Full Version : General questions about combobox



richard.hallier
28 Aug 2008, 10:26 AM
I'm evaluating v1.1alpha2 before starting a new project.

Combo creation :


public class ComboboxPropriete extends ComboBox<BeanModel> {

public ComboboxPropriete(final Class clazz) {
super();

final GeneralServiceAsync service = Registry.get("service");

RpcProxy<ListLoadConfig, ListLoadResult<Propriete>> proxy = new RpcProxy<ListLoadConfig, ListLoadResult<Propriete>>() {
@Override
public void load(ListLoadConfig loadConfig, AsyncCallback<ListLoadResult<Propriete>> callback) {
service.findProprietes(clazz.getName(), callback);
}
};

// loader
final ListLoader<ListLoadConfig> loader = new BaseListLoader<ListLoadConfig, ListLoadResult<Propriete>>(proxy, new BeanModelReader());

ListStore<BeanModel> store = new ListStore<BeanModel>(loader);

setDisplayField("label");
setFieldLabel("Propriete");
setStore(store);
setEditable(false);

loader.load();
}
}
Ok, now, I write my code to populate the form with my model :


selected = one instance of Propriete class
field = form.comboboxProprietes

if (selected != null) {
BeanModel target = field.getStore().findModel("id",selected.getId());
if (target != null)
field.setValue(target);
else
field.setValue(null);
} else
field.setValue(null);

It turns out that the combobox randomly displays the selected item, sometimes it does, sometimes it doesn't...

Could you tell me when do you inititialize a combobox ? Currently I do it between


LayoutContainer wrapper = (LayoutContainer) Registry.get("center");
wrapper.removeAll();
wrapper.add(myFormContainer);
and



wrapper.layout()
Maybe it's wrong? Do we need to initialize the combo when everything is rendered and that the store is loaded ?

Another question, when I dont force the store of the combobox to load at creation time, a lazy renderer is applied. Nice feature but whith this lazy rendering, the store is not still loaded, so field.getStore().findModel("id",selected.getId()) always returns null, therefore I cant set the initial value of the combobox.

Do we need to pre-load all comboboxes when we want to select an item without the ability to take advantage of the lazy renderer?

I also wonder how do you do with comboboxes of lookup models (country, ...) ?
1/ when the app is starting, you load the lookup entities and build a store with them. When you need a combobox, you just create a new combobox with the same store. This solution needs a synchro process to reload store when the lookup entities are updated, store could be managed by the Registry.
2/ Each time a combo is created, a rpc call is done to populate the store, no caching is done. The interest is to be always synchro with the server but increase the server connections

Any thoughts?
Cheers
R.

richard.hallier
29 Aug 2008, 5:14 AM
Ok, I reply to my own previous post.

To solve the problem, I needed 2 things to do :



field.setRawValue((selected != null) ? selected.getLabel() : null); // label is the display field
and

add the following setting :


field.setTriggerAction(TriggerAction.ALL);

R.