Binding not working?

Hi,
I am new to Vaadin, so I think I am doing it the wrong way. I want to write an editor, which list’s the entries of an java.util.List collection in an ListSelect. To be able to add new entries, there is a posibility to open a modal window which allows to enter a new value. Pressing the OK Button there adds the new String to the ListSelect/data collection.

The problem is, when I add it to the ListSelect, or even to the underlying container, it will not be added to the modell collection data. Although I call commit.

I hope, it’s not neccessary to implement an own container for this use case.


public class EnumerationListEditor extends VerticalLayout {

	private static final Logger log = Logger
			.getLogger(EnumerationListEditor.class);

	private final List<String> data;
	private final ListSelect listSelect;
	private String selected;

	private Button removeBtn;
	private Button changeBtn;

	public EnumerationListEditor(List<String> list) {
		this.data = list;
		setSpacing(true);

		listSelect = new ListSelect("Enum Editor", data);
		listSelect.setImmediate(true);
		listSelect.setWriteThrough(true);
		listSelect.setNullSelectionAllowed(false);
		listSelect.setWidth("100%");
		listSelect.addListener(new Property.ValueChangeListener() {
			@Override
			public void valueChange(ValueChangeEvent event) {
				selected = (String) ((Property) event.getProperty()).getValue();
				removeBtn.setEnabled(true);
				changeBtn.setEnabled(true);
			}
		});
		addComponent(listSelect);

		HorizontalLayout buttonBar = new HorizontalLayout();
		buttonBar.setSpacing(true);
		Button newButton = new Button("New");
		newButton.addListener(new ClickListener() {
			@Override
			public void buttonClick(ClickEvent event) {
				log.debug("New enumeration value.");
				AddStringWindow addStringWindow = new AddStringWindow(
						listSelect, data);
				if (addStringWindow.getParent() == null)
					getWindow().addWindow(addStringWindow);
			}
		});
		buttonBar.addComponent(newButton);

		changeBtn = new Button("Change");
		changeBtn.setEnabled(false);
		changeBtn.addListener(new ClickListener() {
			@Override
			public void buttonClick(ClickEvent event) {
				log.debug("change enumeration value");
				if (selected != null) {
					// TODO ändern?
				}
				removeBtn.setEnabled(false);
				changeBtn.setEnabled(false);
			}
		});
		buttonBar.addComponent(changeBtn);

		removeBtn = new Button("Remove");
		removeBtn.setEnabled(false);
		removeBtn.addListener(new ClickListener() {
			@Override
			public void buttonClick(ClickEvent event) {
				log.debug("remove enumeration value");
				if (selected != null)
					listSelect.removeItem(selected);
				removeBtn.setEnabled(false);
				changeBtn.setEnabled(false);
			}
		});
		buttonBar.addComponent(removeBtn);

		// TODO btn save

		Button printDataBtn = new Button("print data");
		printDataBtn.addListener(new ClickListener() {
			@Override
			public void buttonClick(ClickEvent event) {
				for (String string : data) {
					System.out.println("data: " + string);
				}
			}
		});
		buttonBar.addComponent(printDataBtn);
		addComponent(buttonBar);
	}

	private static class AddStringWindow extends Window {

		private AddStringWindow(final ListSelect listSelect,
				final List<String> data) {
			VerticalLayout vl = (VerticalLayout) getContent();
			vl.setMargin(true);
			vl.setSpacing(true);
			setModal(true);
			setCaption("Neuer Enumeration Wert");

			final TextField textField = new TextField();
			textField.setImmediate(true);
			textField.setReadThrough(true);
			textField.focus();
			addComponent(textField);

			HorizontalLayout btnBar = new HorizontalLayout();
			Button okBtn = new Button("OK");
			okBtn.addListener(new ClickListener() {
				@Override
				public void buttonClick(ClickEvent event) {
					getParent().removeWindow(AddStringWindow.this);
					// listSelect.addItem(textField.getValue());
					Container containerDataSource = listSelect.getContainerDataSource();
					containerDataSource.addItem(textField.getValue());
					listSelect.commit();
					
//					data.add((String) textField.getValue());
					
				}
			});
			okBtn.setClickShortcut(KeyCode.ENTER);
			okBtn.setStyleName("primary");
			btnBar.addComponent(okBtn);

			Button cancelBtn = new Button("Cancel");
			cancelBtn.addListener(new ClickListener() {
				@Override
				public void buttonClick(ClickEvent event) {
					getParent().removeWindow(AddStringWindow.this);
				}
			});
			btnBar.addComponent(cancelBtn);
			addComponent(btnBar);
		}
	}
}

edit: just saw, I posted a version without a call to commit. Of course I tried it with commit before.