TextChangeListener & Validation (isValid())

In my application I use a lot of components which I’d like to validate upon change. Detecting change can be done with the TextChangeListener, but I have troubles using the validators for those fields. An example:

	TextChangeListener textChangeListener = new TextChangeListener() {
		public void textChange(TextChangeEvent event) {
			AbstractTextField source = (AbstractTextField) event.getSource();
			System.err.println(event.getText() + " - " + source.getValue());

	TextField textField = new TextField();

Problem is that the value of the TextField is not updated in the textChange event and hence my validation framework (using Vaadin’s built-in isValid() methods on input fields) can only validate the old data. I tried setting the value of the TextField in the textChange event, but then I get into an endless loop (see also http://dev.vaadin.com/ticket/6376 )).

How can this be solved?


We kept the recently introduced textchangevent separate from the value change event as there wouldn’t have been an easy way to distinguish typing and actual value submit (enter/blur).

The endless loop was clearly a bug and is now resolved in the nightly builds of the 6.5 branch. Now it should be possible to do setValue(event.getText()) in text change listener.

However, due to the fact how validation is implemented in Vaadin there might be some synchronization issues in the approach. The TextField is re-rendered on the server side value change and as we don’t block the UI during the server visit, some letters might get dropped. I guess with the LAZY mode and a fast server (low latency) it may work quite fine. If there are some problems I suggest wrapping the TextField into a CustomField (and doing the validation on CustomField level + avoid textfield value changes during text change events). Haven’t tried it, but I’d expect it to work.



Hi Matti,

The latest nightly seems to work. So far I didn’t bump into pieces of text being overwritten by the re-rendering, I’ll do some more tests later (and eventually refactor to CustomField).


Hi guys,
adding text change listener on text field make my page scroll to top of page, do u have any idea why is happening? thnx.