Combo box - collection

{“Male”, “1”, “Female”, “2”} user display “Male” but after click submit button 1 should go to database, In order to this I created class below show it.


import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;

public final class ComboEngine {

    public final Object NAME = "name";
    public final Object SHORT = "short";

    public IndexedContainer getContainer(String[] collectionSet) {
        IndexedContainer c = new IndexedContainer();
        fillContainer(c, collectionSet);
        System.out.println("Calll" + collectionSet);
        return c;
    }

    private void fillContainer(IndexedContainer container, String[] collectionSet) {

        container.addContainerProperty(NAME, String.class,
                null);
        container.addContainerProperty(SHORT, String.class,
                null);

        for (int i = 0; i < collectionSet.length; i++) {
            String name = collectionSet[i++]
;
            String id = collectionSet[i]
;
            Item item = container.addItem(id);
            item.getItemProperty(NAME).setValue(name);
            item.getItemProperty(SHORT).setValue(id);

        }
    }
}

Below show how I use this above class to populate combo box values

first I initialise combo box values

private final String[] sex = new String[]
{"Male", "1", "Female", "2"};

after that I set values like this

   [code]

cmbSex = new ComboBox();
cmbSex.setImmediate(false);
cmbSex.setHeight(“30px”);
cmbSex.setWidth(“75px”);
cmbSex.setCaption(“Sex”);
cmbSex.setNullSelectionAllowed(false);
cmbSex.setInputPrompt(“Sex”);
cmbSex.setTabIndex(4);
cmbSex.setContainerDataSource(combo.getContainer(sex));
cmbSex.setItemCaptionPropertyId(combo.NAME);
mainLayout.addComponent(cmbSex, “top:293.0px;right:1030.0px;bottom:4.0px;left:250.0px;”);
[/code]

If user select “Male” as Sex what I want is after press button that combo box value must change “Female”

How can do it.

Below show how I did it, please correct me if i wrong.

cmbSex.setValue(combo.getContainer(sex).getIdByIndex(0));