Annotation Interface EventData


@Retention(RUNTIME) @Target(PARAMETER) @Documented public @interface EventData
Maps data from a DOM event to a ComponentEvent.

This annotation should be added to parameters in the DOM event constructor in a ComponentEvent, mapped using @DomEvent. See the @DomEvent documentation for more information.

The annotation value() will be evaluated as JavaScript when the event is handled in the browser. The expression is evaluated in a context where element refers to the element for which the listener is registered and event refers to the fired event. The value of the expression is passed back to the server and injected into the annotated ComponentEvent constructor parameter.

Supported parameter types include:

  • Primitives and their wrappers: Integer, Double, Boolean, int, double, boolean, etc.
  • String values: String
  • JSON types: JsonNode
  • Bean/DTO types: Any Java bean or record that can be deserialized from JSON using Jackson
  • Collections: List, Map, etc. (when using generic types with proper bean definitions)

Example with a bean type:

 public class MouseDetails {
     private int clientX;
     private int clientY;
     // getters and setters
 }

 @DomEvent("custom-click")
 public class CustomClickEvent extends ComponentEvent<Component> {
     public CustomClickEvent(Component source, boolean fromClient,
             @EventData("event.detail") MouseDetails details) {
         super(source, fromClient);
         // details is automatically deserialized from the event data
     }
 }
 
Since:
1.0
Author:
Vaadin Ltd
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    A JavaScript expression that will be evaluated to collect data when an event is handled.