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

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.

Henri, thanks very much for your answer.

Marco