PDA

View Full Version : ListStore.findModel is null



q1111
31 Mar 2011, 7:48 PM
ListStore<CommBaseModel> listStore = new ListStore<CommBaseModel>();
RpcProxy<List<CommBaseModel>> proxy = new RpcProxy<List<CommBaseModel>>() {
@Override
protected void load(Object loadConfig,
AsyncCallback<List<CommBaseModel>> callback) {
commBaseService.getCommBaseModelList(tableName, callback);
}
};
ModelReader reader = new ModelReader();
ListLoader<ListLoadResult<CommBaseModel>> loader = new BaseListLoader<ListLoadResult<CommBaseModel>>(proxy, reader);
listStore = new ListStore<CommBaseModel>(loader);
loader.load();

ComboBox commLocation1 = new ComboBox();

commLocation1.setStore(listStore);
commLocation1.setDisplayField(CommBaseModel.ITEMNAME);
commLocation1.setValueField(CommBaseModel.ITEMCODE);
commLocation1.setTriggerAction(TriggerAction.ALL);
commLocation1.setFieldLabel("state");

CommBaseModel m = listStore.findModel(CommBaseModel.ITEMCODE, "120000");

why m is null?

ituren
31 Mar 2011, 8:41 PM
try this:


listStore.addListener(ListStore.DataChanged, new Listener<StoreEvent>() {

@Override
public void handleEvent(StoreEvent be) {
CommBaseModel m = listStore.findModel(CommBaseModel.ITEMCODE, "120000");
}
});

q1111
31 Mar 2011, 9:25 PM
thanks for your reply.
but i want to use commLocation1.setValue(m);

ituren
31 Mar 2011, 9:36 PM
This may be what you want.


listStore.addListener(ListStore.DataChanged, new Listener<StoreEvent>() {

@Override
public void handleEvent(StoreEvent be) {
CommBaseModel m = listStore.findModel(CommBaseModel.ITEMCODE, "120000");
commLocation1.setValue(m);
}
});

q1111
31 Mar 2011, 10:17 PM
it is ok now.thanks

blay
31 Mar 2011, 11:05 PM
Just for pointing what was wrong.
You invoked load method but as it is an asynchronous call, when the "findModel" method is executed, data may be not returned yet.
Adding the listener to the Store.DataChanged event, which is fired when data changes (it seems obvious) on a store because of a loader, you are sure data is in the store.

ituren
31 Mar 2011, 11:07 PM
Just for pointing what was wrong.
You invoked load method but as it is an asynchronous call, when the "findModel" method is executed, data may be not returned yet.
Adding the listener to the Store.DataChanged event, which is fired when data changes (it seems obvious) on a store because of a loader, you are sure data is in the store.

That's the point.
Beginners should be aware of this.

q1111
6 Apr 2011, 2:57 AM
Just for pointing what was wrong.
You invoked load method but as it is an asynchronous call, when the "findModel" method is executed, data may be not returned yet.
Adding the listener to the Store.DataChanged event, which is fired when data changes (it seems obvious) on a store because of a loader, you are sure data is in the store.

Can i get an synchronous call in gxt? I only want to initial UI.

blay
6 Apr 2011, 3:43 AM
No, there are not synchronous calls in GWT