Widget getValue() pattern

I’ve been playing with Vaadin custom widgets, and was wondering how I should implement getValue() in the component.

It seems the shared data is server->client, so if I want to get e.g. a text field’s string back from the client I need to use something else. I obviously don’t want to use RPC to the server on
keystroke when I’m only interested in the final result.


Yes. you don’t want to be sending rpc calls on every key press :slight_smile:

There a several strategies you could use.

The first one is that when the field looses text focus (a tab key is pressed or mouse button clicked somewhere) the value is sent. This is a very common solution. It does however have the downside that server side validation on the value only occurs when you leave the text field.

Another approach is to have a timer with a timeout so that after a certain amount of time of the last keypress the value is sent. This allows for faster validation feedback.

Vaadin’s TextField implements all of these possibilities with TextChangeEvents and their TextChangeEventModes. Looking at AbstractTextField and VTextField might give you a better idea how to implement them.

Fantastic! Thanks, that was a bit of a head-scratcher. Now it all works as expected, using focus and blur listeners.