Combox Reseting value on Form Commit

Hi All,

I’m having a wired problem. In my test application I have a Person class, which has a name, city and country. So in my form, the value for the City depends on the selected Country.

The classes are:

public class Person {
	private String name;
	private City city;
	private Country country;

        //getters and setters

public class Country {

	private String code;
	private String name;
        //getters and setters

public class City {
	private String code;
	private String name;

        //getters and setters

The problem is, when I try to commit the form, the value of City is set to null on the entity. The code for the Form is:

		final Form form = new Form();
		final Person person = new Person();
		form.setFormFieldFactory(new FormFieldFactory() {

			public Field createField(Item item, Object propertyId,
					Component uiContext) {
				if (propertyId.equals("name")) {
					return new TextField((String) propertyId);
				} else {
					return new ComboBox((String) propertyId);
		form.setItemDataSource(new BeanItem(person));

		ComboBox countryComboBox = (ComboBox) form.getField("country");
		countryComboBox.addItem(new Country("US", "United States of America"));
		countryComboBox.addItem(new Country("UK", "United Kindom"));
		countryComboBox.addItem(new Country("MZ", "Mozambique"));

		countryComboBox.addListener(new ValueChangeListener() {
			public void valueChange(ValueChangeEvent event) {
				// here we would query the cities for the selected country
				Country selectedCountry = (Country) event.getProperty()
				List<City> cities = new ArrayList<City>();
				if (selectedCountry.getCode().equals("US")) {
					cities.add(new City("NY", "New York"));
					cities.add(new City("TX", "Texas City"));
				} else if (selectedCountry.getCode().equals("UK")) {
					cities.add(new City("LD", "London"));

				// and then refresh the cities combo
				ComboBox cityComboBox = (ComboBox) form.getField("city");
				for (City city : cities) {

		Button saveButton = new Button("Save", new ClickListener() {
			public void buttonClick(ClickEvent event) {
				System.out.println(person.getCountry()); // prints the object
				System.out.println(person.getCity()); // prints null???? why?

When I get the Person object back, after commiting the form, name and country are setted but city is null. The save button handler will print a Country object and null. What I’m doing wrong?

Thank you.

Just for the record. I found out the problem. For some reason Form.commit() is firing ValueChange and so my listener gets invoked clearing the ComboBox. Is this considered a Vaadin problem or I should use a better Aproach? Any Ideas please?


I am having the same problem and I didn’t noticed it until I saw your message. I’ll flag the commiting operation to prevent the combo reload. How did you solve the issue? Do you know alredy if that is a bug or a feture?


These extraneous value change events can be considered a bug, and are tracked in
ticket 4394

hi… i’m using the version 6.4.7 of the library… and the bug is still there… how i can fix this issue??

At least with my small test programs, I do not see duplicate events in the latest 6.4 version nor in 6.5.

Are you seeing the bug with the code earlier in this thread, or something else. Can you provide a small example on how to reproduce this?