PDA

View Full Version : Combobox hidden value question



ibetts03
21 Nov 2011, 4:40 PM
I have the following combobox:
states.add(StaticData.getStates());
cState = new ComboBox<State>();
cState.setEmptyText("Select a state...");
cState.setDisplayField("statename");
cState.setValueField("abbr");
cState.setWidth(150);
cState.setFieldLabel("State");
cState.addSelectionChangedListener(new SelectionChangedListener<State> ()
{
@Override
public void selectionChanged(SelectionChangedEvent<State> se)
{


Window.alert("State = " + cState.getRawValue());



}
});
cState.setEditable(false);
cState.setVisible(false);
cState.hide();
cState.setStore(states);
cState.setTypeAhead(true);
cState.setTriggerAction(TriggerAction.ALL);
right.add(cState);
My model is:
public State(String abbr, String statename) {
set("abbr", abbr);
set("statename", statename);
}

I can load the store, display the data - however the selected value is not the one in the valuefield - it is the one in the displayfield. I need to be able to access the valuefield (abbreviation) to store it in the database...and I need to keep the displayfield as the text name as well. Does gxt handle name-value pairs? I have tried several variations and none has worked yet.

Ersmarker
3 Jan 2012, 2:34 AM
You can use
se.getSelectedItem(); from the selection event
or cState.getSelection()