PDA

View Full Version : ComboBox display



q1111
6 Apr 2011, 12:14 AM
I hava two ComboBox :commLocation1 and commLocation2. When commLocation1 changed, commLocation2 can get some value. But wnen I init UI, I cannot display commLocation2 and commLocation1 is right. I think commLocation1.addSelectionChangedListener and commLocation1Store.addListener have some problems.
about the source is:
public ComboBox commLocation1 = new ComboBox();
private ComboBox commLocation2 = new ComboBox();

commLocation1Store = CommUtilService.getLocationByParentId("");
if(hspConfigBaseinfoModel.getCommLocation1() != null && hspConfigBaseinfoModel.getCommLocation1().trim().length() > 0){
commLocation2Store = CommUtilService.getLocationByParentId(hspConfigBaseinfoModel.getCommLocation1());
}

commLocation1.setStore(commLocation1Store);
commLocation1.setDisplayField(CommBaseModel.ITEMNAME);
commLocation1.setValueField(CommBaseModel.ITEMCODE);
commLocation1.setTriggerAction(TriggerAction.ALL);
commLocation1.setFieldLabel("province");
commLocation1.addSelectionChangedListener(
new SelectionChangedListener<CommBaseModel>() {
@Override
public void selectionChanged(SelectionChangedEvent<CommBaseModel> se) {
commLocation2.clearSelections();
commLocation2.getStore().removeAll();
String parentId = se.getSelectedItem().getItemCode();
commBaseService.getLocationList(parentId,
new AsyncCallback<List<CommBaseModel>> () {
@Override
public void onSuccess(List<CommBaseModel> list) {
commLocation2Store.add(list);
}
@Override
public void onFailure (Throwable caught) {
CenterDebug.print(caught.toString());
}
}
);

}
}
);
commLocation1.addKeyListener(new CenterKeyListener(commLocation2));
commLocation1Store.addListener(ListStore.DataChanged,
new Listener<StoreEvent>() {
@Override
public void handleEvent(StoreEvent be) {
CommBaseModel model = commLocation1Store.findModel(CommBaseModel.ITEMCODE, hspConfigBaseinfoModel.getCommLocation1());
commLocation1.setValue(model);
}
}
);

commLocation2.setStore(commLocation2Store);
commLocation2.setDisplayField(CommBaseModel.ITEMNAME);
commLocation2.setValueField(CommBaseModel.ITEMCODE);
commLocation2.setTriggerAction(TriggerAction.ALL);
commLocation2.setFieldLabel("county");
commLocation2.addKeyListener(new CenterKeyListener(commLocation3));
commLocation2Store.addListener(ListStore.DataChanged,
new Listener<StoreEvent>() {
@Override
public void handleEvent(StoreEvent be) {
CommBaseModel model = commLocation2Store.findModel(CommBaseModel.ITEMCODE, hspConfigBaseinfoModel.getCommLocation2());
commLocation2.setValue(model);
commLocation2.fireEvent(Events.Refresh);
}
}
);