Package com.vaadin.flow.dom
Class DomEvent
- java.lang.Object
-
- java.util.EventObject
-
- com.vaadin.flow.dom.DomEvent
-
- All Implemented Interfaces:
Serializable
public class DomEvent extends EventObject
Server-side representation of a DOM event fired in the browser.- Since:
- 1.0
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class java.util.EventObject
source
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description elemental.json.JsonObjectgetEventData()Gets additional data related to the event.Optional<Element>getEventDataElement(String eventDataExpression)Gets the closestElementcorresponding to the given event data expression.Optional<Element>getEventTarget()Gets the closestElementthat corresponds to theevent.targetfor the DOM event.DebouncePhasegetPhase()Gets the debounce phase for which this event is fired.ElementgetSource()Returns the element on which the listener has been attached.StringgetType()Gets the type of the event.-
Methods inherited from class java.util.EventObject
toString
-
-
-
-
Constructor Detail
-
DomEvent
public DomEvent(Element source, String eventType, elemental.json.JsonObject eventData)
Creates a new DOM event.- Parameters:
source- the element on which the listener has been attached, notnulleventType- the type of the event, notnulleventData- additional data related to the event, notnull- See Also:
Element.addEventListener(String, DomEventListener),DomEventListener
-
-
Method Detail
-
getSource
public Element getSource()
Returns the element on which the listener has been attached.- Overrides:
getSourcein classEventObject- Returns:
- The element on which the listener has been attached.
- See Also:
Element.addEventListener(String, DomEventListener),for event target element
-
getType
public String getType()
Gets the type of the event.- Returns:
- the type of the event
-
getEventData
public elemental.json.JsonObject getEventData()
Gets additional data related to the event. An empty JSON object is returned if no event data is available.- Returns:
- a JSON object containing event data, never
null - See Also:
DomListenerRegistration.addEventData(String)
-
getPhase
public DebouncePhase getPhase()
Gets the debounce phase for which this event is fired. This is used internally to only deliver the event to the appropriate listener in cases where there are multiple listeners for the same event with different debounce settings.- Returns:
- the debounce phase
-
getEventTarget
public Optional<Element> getEventTarget()
Gets the closestElementthat corresponds to theevent.targetfor the DOM event. This is always inside the child hierarchy of the element returned bygetSource().To get this reported, you need to call
DomListenerRegistration.mapEventTargetElement()or an empty optional is always returned.The returned element is the same as
getSource()only if the event originated from that element on the browser (and not from its child).- Returns:
- the element that corresponds to
event.targetor an empty optional - Since:
- 9.0
-
getEventDataElement
public Optional<Element> getEventDataElement(String eventDataExpression)
Gets the closestElementcorresponding to the given event data expression. NOTE: this only works if you have added the expression usingDomListenerRegistration.addEventDataElement(String).If the evaluated JS expression returned an element that is not created or controlled by the server side, the closest parent element that is controlled is returned instead. Invisible elements are not reported.
In case you want the
event.targetelement, usegetEventTarget()instead.- Parameters:
eventDataExpression- the expression that was executed on the client to retrieve the element, notnull- Returns:
- the element that corresponds to the given expression or an empty optional
- Since:
- 9.0
-
-