Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Field.ValueChangeEvent -- How is this ever used?
From what I can tell, the API for TextField and such only involves Property.ValueChangeEvent, not Field.ValueChangeEvent.
So when does Field.ValueChangeEvent come into play?
I would like to be receiving Field.ValueChangeEvent events, so I can get back to the UI component that the user manipulated.
--Basil Bourque
Property.ValueChangeEvent is an interface, which is implemented by several concrete event types. So by the API you should not be interested by the source of the event. However in reality it would be very convenient to know it. You could cast the event to Field.ValueChangeEvent. (ugly)
I see. Thanks for the answer.
This interface is what is used by the event mechanisms in Vaadin:
• Property.ValueChangeEvent
And the implementations actually used may be either:
• Field.ValueChangeEvent
• Label.ValueChangeEvent
So, when you receive a Property.ValueChangeEvent, you can try casting it to either of those Field. or Label. implementations. After casting to the Field. implementation, you have access to the extra methods such as "getComponent".
Example method:
/**
* Implements Property.ValueChangeListener
*
* @see com.vaadin.data.Property.ValueChangeListener#valueChange(com.vaadin.data.Property.ValueChangeEvent)
*/
@Override
public void valueChange( ValueChangeEvent event ) {
System.out.println( "DEBUG - The Application's 'valueChange' method is executing." + new java.util.Date() );
if ( event instanceof Field.ValueChangeEvent ) {
System.out.println( "DEBUG - Yes, event passed is a Field.ValueChangeEvent." );
Field.ValueChangeEvent fieldEvent =[color=#01c63c] (Field.ValueChangeEvent)event[/color]; // [color=#1e95fd]Cast[/color] the Property.VCE interface to a Field.VCE implementation.
Component sourceComponent = fieldEvent.[color=#01c63c]getComponent()[/color]; // After casting, access [color=#1e95fd]additional methods[/color].
if ( sourceComponent instanceof com.vaadin.data.Validatable ) {
com.vaadin.data.Validatable validatable = (com.vaadin.data.Validatable)sourceComponent ;
boolean widgetIsValid = validatable.isValid(); // The goal in my particular use-case.
}
}
}