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.
FieldEvents.BlurEvent
Hi,
I refer to the page https://vaadin.com/book/-/page/application.events.html, discussing different ways to intercepts and handle events.
I'm curious about the following not working:
[...]
this.username = new TextField();
// alternative #1: it works
this.username.addListener((FieldEvents.BlurListener)this);
// alternative #2: does not work
this.username.addListener(FieldEvents.BlurEvent.class, this, "blur");
addComponent(this.username);
public void blur(FieldEvents.BlurEvent event) {
[...]
}
[...]
I get no errors, but the second way of adding a listener has no consequences (either the event is not fired or it is not intercepted).
Thanks, Marco
More explicitly, it seems to me that:
public void addListener(Class<?> eventType, Object target, String methodName) {}
does not work when eventType is FieldEvents.BlurEvent (while, for example, it works for Button.ClickEvent).
Thanks,
Marco
Marco Zanon: public void addListener(Class<?> eventType, Object target, String methodName) {}
This method (which the javadoc discourages from using) does not tell the client that it should send such events to the server - unless someone else has registered a listener with the appropriate API, no events are sent by the client. It works directly with events that are generated on the server side, though.
I would recommend using the addListener(listenerImplementation) method. If you absolutely need to register a listener using an arbitrary method, see the protected method AbstractComponent.addListener(eventIdentifier, eventType, target, method) that is used by addListener(FocusListener) etc.