Class ElementListenerMap

All Implemented Interfaces:
Serializable

public class ElementListenerMap extends NodeMap
Map of DOM events with server-side listeners. The key set of this map describes the event types for which listeners are present. The values associated with the keys are currently not used.

For internal use only. May be renamed or removed in a future release.

Since:
1.0
Author:
Vaadin Ltd
See Also:
  • Field Details

    • ALWAYS_TRUE_FILTER

      public static final String ALWAYS_TRUE_FILTER
      Dummy filter string that always passes. The client runs it without compiling it.
      See Also:
  • Constructor Details

    • ElementListenerMap

      public ElementListenerMap(StateNode node)
      Creates a new element listener map for the given node.
      Parameters:
      node - the node that the map belongs to
  • Method Details

    • isCompiledByClient

      public static boolean isCompiledByClient(String eventData)
      Checks whether the client compiles the given event data from a string. The client reads a synchronized property, the state node closest to the event target or a property path, also one that leads to the element to map to a state node, and calls preventDefault() or stopPropagation(), without compiling anything.
      Parameters:
      eventData - the event data, as passed to DomListenerRegistration.addEventData(String), not null
      Returns:
      true if the client compiles the event data with new Function, which a content security policy without unsafe-eval does not allow
    • add

      public DomListenerRegistration add(String eventType, DomEventListener listener)
      Add eventData for an event type.
      Parameters:
      eventType - the event type
      listener - the listener to add
      Returns:
      a handle for configuring and removing the listener
    • producePutChange

      protected boolean producePutChange(String key, boolean hadValueEarlier, Serializable newValue)
      Description copied from class: NodeMap
      Checks whether a MapPutChange should be produced.
      Overrides:
      producePutChange in class NodeMap
      Parameters:
      key - a key to produce a change
      hadValueEarlier - whether the value was already earlier in the map
      newValue - the new value for the key
      Returns:
      true if a change should be produced, false otherwise
    • collectChanges

      public void collectChanges(Consumer<NodeChange> collector)
      Description copied from class: NodeFeature
      Collects all changes that are recorded for this feature.
      Overrides:
      collectChanges in class NodeMap
      Parameters:
      collector - a consumer accepting node changes
    • fireEvent

      public void fireEvent(DomEvent event)
      Fires an event to all listeners registered for the given type.
      Parameters:
      event - the event to fire
    • getExpressions

      public Set<String> getExpressions(String eventName)
      Gets the event data expressions defined for the given event name. This method is currently only provided to facilitate unit testing.
      Parameters:
      eventName - the name of the event, not null
      Returns:
      an unmodifiable set of event data expressions, not null
      Since:
      3.0
    • getSnippetEntries

      public Set<ElementListenerMap.SnippetEntry> getSnippetEntries(String eventName)
      Gets the declared snippets that the client runs for the given event name: the filters and the event data that are declared as JavaScript functions of the bundle instead of as expressions. Together with getExpressions(String), this is everything the client runs when the event occurs. This method is currently only provided to facilitate testing, such as simulating events on the server.
      Parameters:
      eventName - the name of the event, not null
      Returns:
      an unmodifiable set of the declared snippets, not null
    • isPropertyPath

      public static boolean isPropertyPath(String expression)
      Checks whether the given expression is a property path that the browser reads without compiling it: event or element followed by property names that each start with . or ?..
      Parameters:
      expression - the expression to check, not null
      Returns:
      true if the expression is a property path, false otherwise
    • addEventData

      public static void addEventData(DomListenerRegistration registration, List<String> eventData)
      Adds event data to a registration. Reports the event data that the browser compiles from a string, which is any data other than a property path or a token of the internal data that Flow adds, such as a synchronized property. Keeps the given list if it is unmodifiable and the registration has no event data yet, so that listeners that add the same data can share one list.

      A registration that is not one of this map gets each value with DomListenerRegistration.addEventData(String).

      Parameters:
      registration - the registration to add the event data to, not null
      eventData - the event data, not null and not containing null
      Throws:
      CspViolationException - in the CspMode.STRICT Content Security Policy mode, if any value is compiled by the browser
    • addEventDataWithoutCspReport

      public static void addEventDataWithoutCspReport(DomListenerRegistration registration, List<String> eventData)
      Adds event data to a registration of this map like addEventData(DomListenerRegistration, List), but without reporting them as JavaScript sent as a string. For the keys of data that client code builds and sends with sendEventMessage, which the client never compiles.
      Parameters:
      registration - a registration returned by add(String, DomEventListener), not null
      eventData - the keys of the event data, not null and not containing null
    • addBundledEventData

      public static void addBundledEventData(DomListenerRegistration registration, List<String> eventData)
      Adds EventData values to a registration of this map like addEventData(DomListenerRegistration, List), for values that the build has put into the bundle as functions, see BundledEventData. The client runs the function of the bundle instead of compiling the value, and sends the result under the value, so nothing is reported as JavaScript sent as a string.
      Parameters:
      registration - a registration returned by add(String, DomEventListener), not null
      eventData - the event data values, not null and not containing null
    • getEventDataKey

      public static String getEventDataKey(DomEventData<?> eventData)
      Gets the key that the client sends the value of the given event data under. The key does not change after the event data is created.
      Parameters:
      eventData - the event data, not null
      Returns:
      the key of the value, not null
    • getPropertySynchronizationMode

      public DisabledUpdateMode getPropertySynchronizationMode(String propertyName)
      Gets the most permissive update mode for any event registration that is configured to synchronize the given property.
      Parameters:
      propertyName - the property name to check, not null
      Returns:
      the most permissive update mode, or null if synchronization is not configured for the given property
      Since:
      1.3
    • hasAllowInertForProperty

      public boolean hasAllowInertForProperty(String propertyName)
      Returns true if any listener for the given property has allowInert enabled. Note that this means that enabling allowInert for any listener for a certain property will effectively allow it for all listeners for said property.
      Parameters:
      propertyName - the property name to check, not null
      Returns:
      true if allowInert is enabled for any listener for the given property, false otherwise
      Since:
      24.6.8