PDA

View Full Version : Getting values from a ComboBox, only get rawValue()



jamone
29 May 2012, 11:24 PM
First I have gone through all the threads regarding getting ComboBox values and found non of them helpful.

So I would request that any Sencha developer who responds to this thread please give us a definitive, sure fire way to retrieve values from a ComboBox.

My issue, I have a ComboBox that displays items from a Store: StatusCodes2

public StatusCodes2(String conceptCode, String name, Integer internalId) {
set("conceptCode", conceptCode);
set("name", name);
set("internalId", internalId);
}

public static List<StatusCodes2> getStatusCodes2() {
List<StatusCodes2> statusCodes2 = new ArrayList<StatusCodes2>();

statusCodes2.add(new StatusCodes2("CACC", "Certified anatomic pathology and clinical pathology care", 21848));
statusCodes2.add(new StatusCodes2("CAIC", "Certified allergy and immunology care", 21830));
statusCodes2.add(new StatusCodes2("CAMC", "Certified aerospace medicine care", 21854));

return statusCodes2;
}

My ComboBox is: ComboBox<StatusCodes2> combo;

The ComboBox displays correctly and show the proper choices.

List<StatusCodes2> statusCodes = TestData.getStatusCodes2();
ListStore<StatusCodes2> store = new ListStore<StatusCodes2>();
store.add(statusCodes);

combo = new ComboBox<StatusCodes2>();
combo.setFieldLabel("Status Codes");
combo.setDisplayField("name");
combo.setValueField("conceptCode");
combo.setTriggerAction(TriggerAction.ALL);
combo.setStore(store);
combo.setAllowBlank(false);

combo.addListener(Events.SelectionChange, new Listener<SelectionChangedEvent<StatusCodes2>>() {

@Override
public void handleEvent(SelectionChangedEvent<StatusCodes2> be) {
System.out.println("ComboBox getConceptCode: " + be.getSelectedItem().getConceptCode());
System.out.println("ComboBox getName: " + be.getSelectedItem().getName());
System.out.println("ComboBox getInternalId: " + be.getSelectedItem().getInternalId());
}

});

I have a Submit button which when I click the button I would like the selected List<StatusCodes2> to be returned, these are all the values I have printed out and their outputs.

System.out.println("combo.getSelection() value: " + combo.getSelection().get(0));
System.out.println("combo.getValue() value: " + combo.getValue());
System.out.println("combo.getSelection().toArray().toString() value: " + combo.getSelection().toArray().toString());
System.out.println("combo.getSelectedText() value: " + combo.getSelectedText());

ListStore<StatusCodes2> rStore = combo.getStore();
int li = rStore.indexOf(combo.getValue());
System.out.println("rStore.indexOf(combo.getValue()): " + li);
System.out.println("Combo selected store: " + combo.getStore().getAt(li));
System.out.println("combo.getRawValue() value: " + combo.getRawValue());

Output:


ComboBox getConceptCode: null
ComboBox getName: null
ComboBox getInternalId: null

combo.getSelection() value: null
combo.getValue() value: null
combo.getSelection().toArray().toString() value: [Ljava.lang.Object;@89d82b
combo.getSelectedText() value:
rStore.indexOf(combo.getValue()): 2
Combo selected store: null
combo.getRawValue() value: Certified aerospace medicine care

The only value I can get is the raw value, the rStore.indexOf(combo.getValue()) is correct, but I cannot get any values from my store using that index.

So please, how do I get the selected value, why is only the rawValue working and getValue shows null?

Thanks in advance.

Cheers.