Class ClientDomEvent
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(), stopPropagation()
and getModifierState() 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 whether the default action was prevented
cannot be known, and isDefaultPrevented() fails. The event can still
be fired, for callers that don't need to know.
Filters and event data declared as JavaScript functions of the bundle, rather
than as expressions, are run by a DeclaredFunctionSimulation of the
declared function, registered by its @JsDefinition interface. Event
data declared by a function without a simulation is left out, like an
unsupported expression. A filter declared by a function without a simulation
does not match, and as its body cannot be inspected, whether it prevented the
default action cannot be known: isDefaultPrevented() fails.
For internal use only.
-
Method Summary
Modifier and TypeMethodDescriptionstatic ClientDomEventDispatches 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.static ClientDomEventdispatchKeyDown(Element element, Key key, Collection<? extends Key> modifiers) Dispatches akeydownevent of the given key on the given element, with the given modifiers pressed, the way the browser does when the user presses the keys.voidfire()Sends the event to the server, running the listeners whose filter matched.booleanGets whether an expression calledevent.preventDefault()while the event was dispatched.
-
Method Details
-
dispatch
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(). -
dispatchKeyDown
public static ClientDomEvent dispatchKeyDown(Element element, Key key, Collection<? extends Key> modifiers) Dispatches akeydownevent of the given key on the given element, with the given modifiers pressed, the way the browser does when the user presses the keys. The event has both thekeyand thecodeof the key, seeKeyboardKey. Seedispatch(Element, String, Map).- Parameters:
element- the element the event is dispatched on, notnullkey- the pressed key, notnullmodifiers- the modifiers held down while the key is pressed, notnull- Returns:
- the dispatched event
-
isDefaultPrevented
public boolean isDefaultPrevented()Gets whether an expression calledevent.preventDefault()while the event was dispatched.- Returns:
trueif the default action of the event was prevented- Throws:
IllegalStateException- if a registered expression that callspreventDefault(), or a declared filter, cannot be run without a browser
-
fire
public void fire()Sends the event to the server, running the listeners whose filter matched.
-