ValueChangeListener doesn't work

Hi,
I’m reading Book of Vaadin and got stuck on chapter 9. I tried to run following example:

package com.example.test;

import com.vaadin.Application;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.*;

public class TestApplication extends Application {
	@Override
	public void init() {
		final Window mainWindow = new Window("Test Application");
		final TextField tf = new TextField("Name");

		// Set the value
		tf.setValue("The text field value");

		// When the field value is edited by the user
		tf.addListener(new Property.ValueChangeListener() {
			public void valueChange(ValueChangeEvent event) {
				// Get the value and cast it to proper type
				String value = (String) tf.getValue();

				// Do something with it

				mainWindow.addComponent(new Label(value));
			}
		});
		mainWindow.addComponent(tf);
		setMainWindow(mainWindow);

	}

}

Problem is, that after value change in text field nothing happens. Why? What should I change in this code?

regards,
Rob

Hi,

the code seems to be missing this:

tf.setImmediate(true);

When the TextField is non-immediate, the value is sent to the server only on the next round-trip (e.g. the user presses a button).


Tepi

Thanks, I added this line and it’s works :slight_smile:

No problem :).

I created a
ticket
about the example so the book can be made better.


Tepi

There is somewhat similar problem with check boxes in
BoV
. Without reading this thread I would probably still be wondering why valueChange didn’t work. :open_mouth: