Class ClientDomEvent

java.lang.Object
com.vaadin.browserless.internal.ClientDomEvent

public final class ClientDomEvent extends Object
A DOM event as the browser dispatches it to the Flow client.

When the browser dispatches an event, the Flow client evaluates every JavaScript expression the server registered for that event type — event data expressions, listener filters and the event.preventDefault() calls added by DomListenerRegistration.preventDefault() — against the native event object, and sends the results to the server as the event data. This class does the same for a simulated event, so that filtered listeners see the same data as in the browser, and whether a listener prevented the default action is known when the event is dispatched, as in the browser.

Only the subset of JavaScript that such expressions use is supported: property reads and the preventDefault() and stopPropagation() calls on event, literals, !, &&, ||, comparisons and parentheses. An expression outside that subset is left out of the event data, as if it were undefined, unless it calls preventDefault(): then the outcome of the event cannot be known and dispatching fails.

For internal use only.

  • Method Summary

    Modifier and Type
    Method
    Description
    dispatch(Element element, String type, Map<String,?> properties)
    Dispatches an event of the given type on the given element, the way the browser does: the registered expressions are evaluated against an event object with the given properties, giving the event data and whether the default action was prevented.
    void
    Sends the event to the server, running the listeners whose filter matched.
    boolean
    Gets whether an expression called event.preventDefault() while the event was dispatched.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • dispatch

      public static ClientDomEvent dispatch(Element element, String type, Map<String,?> properties)
      Dispatches an event of the given type on the given element, the way the browser does: the registered expressions are evaluated against an event object with the given properties, giving the event data and whether the default action was prevented.

      The event is not yet sent to the server, see fire().

      Parameters:
      element - the element the event is dispatched on, not null
      type - the event type, e.g. click, not null
      properties - the properties of the native event object, e.g. button; values are Boolean, Number or String
      Returns:
      the dispatched event
      Throws:
      IllegalStateException - if a registered expression that calls preventDefault() uses JavaScript that cannot be evaluated without a browser
    • isDefaultPrevented

      public boolean isDefaultPrevented()
      Gets whether an expression called event.preventDefault() while the event was dispatched.
      Returns:
      true if the default action of the event was prevented
    • fire

      public void fire()
      Sends the event to the server, running the listeners whose filter matched.