How to update items in a combobox

I have some combos. Combobox “merkki” includes cars like alfa Romeo, Alpina, AMC, Auburn, Audi, Austin … When a new car is selected in “merkki” a listener picks up from database new items for “malli” combobox to String comboItems. “malli is populated with a sample row”

Question:
How to update “malli” combobox from the array of comboItems so that Property.ValueChangeListener can still listen it?

Tapani

This is model for combos:

public class CombosModel {
	String lkm = "";
	String merkki;
	String malli;
	String valmVuosiP;
	String valmVuosiS;
	...
	+ some other Strings for combos
	+ getters and setters
}

Main code begins here:

public class PopulateCombos extends Form implements ValueChangeListener {	
		
	final CombosModel comboDataModel = new CombosModel();
	HakuLauseVaadin hakuLauseVaadin = new HakuLauseVaadin();
	Boolean listaVaiLukumäärä = false;
	Map<String, String> map = new TreeMap(); // sorted map
	String[] comboItems;
	String rivienMäärä = "";
Data model for combos
    [code]

public void setDataSource() {
setItemDataSource(new BeanItem(comboDataModel));
setVisibleItemProperties(order);
getField(“lkm”).setDescription(“Osumien määrä”);
[/code]
Populate combos from database
[code]
for (int i = 1; i < order.length; i++) {
comboItems = hakuLauseVaadin.alkuarvotComboboxiin(order[i]
);
replaceWithSelect(order[i]
, comboItems, comboItems)
.setNewItemsAllowed(false);
getField(order[i]
).addListener(valintaListener);
getField(order[i]
).setDescription(
"Valitse " + ohje[i]

  • “. Ei ole pakollinen.”);
    }
    setImmediate(true);
    setWriteThrough(false);
    [/code]
    Number of rows
    getField("lkm").setValue( hakuLauseVaadin.merkkiCountVaadin(map, listaVaiLukumäärä)); }
    listener
	Property.ValueChangeListener valintaListener = new Property.ValueChangeListener() {
		public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
			map = new TreeMap();
			listaVaiLukumäärä = false;
			for (int i = 1; i < order.length; i++) {
				String arvo = getField(order[i]
).toString();
				if (arvo != null) {
					map.put(order[i]
, arvo);
				}
				if (order[i]
.equals("merkki")) {
					comboItems = hakuLauseVaadin
							.alkuarvotMalliComboboxiin(getField("merkki")
									.toString());
				}
			}
			...
		}
	};
}	

Hi,

It would help if you could use english in your code.

Thanks.

Hi Edrisse,
You can see similar code here:
http://demo.vaadin.com/docs/example-source/com/vaadin/demo/featurebrowser/FormExample.java.htm

If you populate combobox of “city” like this line in that example:

replaceWithSelect("city", cities, cities).setNewItemsAllowed(true);

My question is:
How can you remove items from “citiy” and set new items to “citiy”?

You can find “cities” in public class FormExample extends CustomComponent { static final String cities[] = { "Amsterdam", ...
and “citiy” in public static class Address { String name = ""; String streetAddress = ""; String postalCode = ""; String city;
This line creates a combobox and some TextFields: setItemDataSource(new BeanItem(dataModel));

Tapani

In order to add/remove options from selects, use add/removeItem() methods.