chalu
18 Aug 2010, 10:04 PM
This has been a show stopper for me, I have a Class that acts like a repository of stores in my app, its called DataCenter, I did this so I can build my stores (for combos) once and then use them all over the app from there.
public class DataCenter extends BaseObservable {
public static final String SEMESTERTYPE_LIST_STORE = "semestertype_list_store";
public static final String PROGRAMME_LEVELS_LIST_STORE = "programme_levels_list_store";
....
private void semesterTypeListStore() {
RpcProxy<ListLoadResult<SemesterType>> rpcProxy = new RpcProxy<ListLoadResult<SemesterType>>() {
@Override
public void load(Object loadConfig, AsyncCallback<ListLoadResult<SemesterType>> callback) {
rpcService.listSemesterTypes(callback);
}
};
ListLoader<ListLoadResult<ModelData>> loader;
loader = new BaseListLoader<ListLoadResult<ModelData>>(rpcProxy, new BeanModelReader());
ListStore<BeanModel> store = new ListStore<BeanModel>(loader);
Registry.register(SEMESTERTYPE_LIST_STORE, store);
}
private void programmeLevelsListStore() {
RpcProxy<ListLoadResult<ProgrammeLevel>> rpcProxy = new RpcProxy<ListLoadResult<ProgrammeLevel>>(){
@Override
public void load(Object loadConfig, AsyncCallback<ListLoadResult<ProgrammeLevel>> callback) {
rpcService.listProgrammeLevels((ListLoadConfig) loadConfig, callback);
}
};
ListLoader<ListLoadResult<ModelData>> loader;
loader = new BaseListLoader<ListLoadResult<ModelData>>(rpcProxy, new BeanModelReader());
ListStore<BeanModel> store = new ListStore<BeanModel>(loader);
Registry.register(PROGRAMME_LEVELS_LIST_STORE, store);
}
}
With this, my combos are loaded thus :
ComboBox<BeanModel> semesterCb = new ComboBox<BeanModel>();
semesterCb.setValueField("id");
semesterCb.setDisplayField("name");
semesterCb.setForceSelection(true);
semesterCb.setFieldLabel("Semester");
semesterCb.setTriggerAction(ComboBox.TriggerAction.ALL);
semesterCb.setStore((ListStore<BeanModel>) Registry.get(DataCenter.SEMESTERTYPE_LIST_STORE));
So I can just use setStore((ListStore<BeanModel>) Registry.get(DataCenter.SEMESTERTYPE_LIST_STORE));
wherever I need to list Semester in a combo, and it works perfect.
The problem however arises when I need to pass a parameter to the server with which the combo should be loaded, here is what I tried :
// I am trying to list the levels (years of study) in a University program
ComboBox<BeanModel> levelCb = new ComboBox<BeanModel>();
levelCb.setValueField("id");
levelCb.setDisplayField("name");
levelCb.setForceSelection(true);
levelCb.setFieldLabel("Level");
levelCb.setTriggerAction(ComboBox.TriggerAction.ALL);
ListStore<BeanModel> leveListStore = Registry.get(DataCenter.PROGRAMME_LEVELS_LIST_STORE);
levelCb.setStore(leveListStore);
BaseListLoadConfig cfg = new BaseListLoadConfig();
cfg.set("programme", programme); // I need to tell the server to list levels for this "progrmme"
leveListStore.getLoader().load(cfg);
When the form window opens, the leveListStore is loaded and with logging I can see on the server that the "programme" is sent along with the request, however when the "trigger" button of the combo is clicked, the "programme" is not sent to the server (obviously), so I end up with a NullPointer exception in my processing. The question is how do I send parameters when loading the combos WITHOUT breaking the structure of DataCenter, maybe a way to override the triggerAction (without a subclass) for such combo.
I looked at the code in onTriggerClick method of ComboBox in GXT and noticed that it uses the allQuery field which is just a String, so I have decided to also try to send maybe the id of the "programme" as a string instead of the "programme" object itself, but how is it passed to the server method, as a parameter ??
Please I need help with this. Cheers.
public class DataCenter extends BaseObservable {
public static final String SEMESTERTYPE_LIST_STORE = "semestertype_list_store";
public static final String PROGRAMME_LEVELS_LIST_STORE = "programme_levels_list_store";
....
private void semesterTypeListStore() {
RpcProxy<ListLoadResult<SemesterType>> rpcProxy = new RpcProxy<ListLoadResult<SemesterType>>() {
@Override
public void load(Object loadConfig, AsyncCallback<ListLoadResult<SemesterType>> callback) {
rpcService.listSemesterTypes(callback);
}
};
ListLoader<ListLoadResult<ModelData>> loader;
loader = new BaseListLoader<ListLoadResult<ModelData>>(rpcProxy, new BeanModelReader());
ListStore<BeanModel> store = new ListStore<BeanModel>(loader);
Registry.register(SEMESTERTYPE_LIST_STORE, store);
}
private void programmeLevelsListStore() {
RpcProxy<ListLoadResult<ProgrammeLevel>> rpcProxy = new RpcProxy<ListLoadResult<ProgrammeLevel>>(){
@Override
public void load(Object loadConfig, AsyncCallback<ListLoadResult<ProgrammeLevel>> callback) {
rpcService.listProgrammeLevels((ListLoadConfig) loadConfig, callback);
}
};
ListLoader<ListLoadResult<ModelData>> loader;
loader = new BaseListLoader<ListLoadResult<ModelData>>(rpcProxy, new BeanModelReader());
ListStore<BeanModel> store = new ListStore<BeanModel>(loader);
Registry.register(PROGRAMME_LEVELS_LIST_STORE, store);
}
}
With this, my combos are loaded thus :
ComboBox<BeanModel> semesterCb = new ComboBox<BeanModel>();
semesterCb.setValueField("id");
semesterCb.setDisplayField("name");
semesterCb.setForceSelection(true);
semesterCb.setFieldLabel("Semester");
semesterCb.setTriggerAction(ComboBox.TriggerAction.ALL);
semesterCb.setStore((ListStore<BeanModel>) Registry.get(DataCenter.SEMESTERTYPE_LIST_STORE));
So I can just use setStore((ListStore<BeanModel>) Registry.get(DataCenter.SEMESTERTYPE_LIST_STORE));
wherever I need to list Semester in a combo, and it works perfect.
The problem however arises when I need to pass a parameter to the server with which the combo should be loaded, here is what I tried :
// I am trying to list the levels (years of study) in a University program
ComboBox<BeanModel> levelCb = new ComboBox<BeanModel>();
levelCb.setValueField("id");
levelCb.setDisplayField("name");
levelCb.setForceSelection(true);
levelCb.setFieldLabel("Level");
levelCb.setTriggerAction(ComboBox.TriggerAction.ALL);
ListStore<BeanModel> leveListStore = Registry.get(DataCenter.PROGRAMME_LEVELS_LIST_STORE);
levelCb.setStore(leveListStore);
BaseListLoadConfig cfg = new BaseListLoadConfig();
cfg.set("programme", programme); // I need to tell the server to list levels for this "progrmme"
leveListStore.getLoader().load(cfg);
When the form window opens, the leveListStore is loaded and with logging I can see on the server that the "programme" is sent along with the request, however when the "trigger" button of the combo is clicked, the "programme" is not sent to the server (obviously), so I end up with a NullPointer exception in my processing. The question is how do I send parameters when loading the combos WITHOUT breaking the structure of DataCenter, maybe a way to override the triggerAction (without a subclass) for such combo.
I looked at the code in onTriggerClick method of ComboBox in GXT and noticed that it uses the allQuery field which is just a String, so I have decided to also try to send maybe the id of the "programme" as a string instead of the "programme" object itself, but how is it passed to the server method, as a parameter ??
Please I need help with this. Cheers.