Class ComponentEvent<T extends Component>

java.lang.Object
java.util.EventObject
com.vaadin.flow.component.ComponentEvent<T>
Type Parameters:
T - the event source type
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AbstractAttachDetachEvent, AbstractField.ComponentValueChangeEvent, BlurNotifier.BlurEvent, ClickEvent, CompositionEvent, FocusNotifier.FocusEvent, InputEvent, KeyboardEvent, PollEvent, UI.BrowserLeaveNavigationEvent, UI.BrowserNavigateEvent, UI.BrowserRefreshEvent, UploadCompleteEvent, UploadStartEvent, WebComponentUI.WebComponentConnectEvent

public class ComponentEvent<T extends Component> extends EventObject
An event whose source is a Component.

Typically used together with ComponentEventBus.

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

    • ComponentEvent

      public ComponentEvent(T source, boolean fromClient)
      Creates a new event using the given source and indicator whether the event originated from the client side or the server side.
      Parameters:
      source - the source component
      fromClient - true if the event originated from the client side, false otherwise
  • Method Details

    • getSource

      public T getSource()
      Overrides:
      getSource in class EventObject
    • getUI

      public UI getUI()
      Gets the UI the source component is attached to.

      This is a convenience for getSource().getUI().get() when the event is fired while the source is attached to a UI, which is the common case.

      If the source component is not currently attached to a UI, this method throws an IllegalStateException. This can happen, for example, when an initial value is set on a field before it is added to the UI and a value-change listener is invoked. If your listener can run while the source is detached, use getSource().getUI() instead, which returns an Optional and lets you handle the detached case explicitly.

      Returns:
      the UI the source component is attached to, never null
      Throws:
      IllegalStateException - if the source component is not currently attached to a UI
    • isFromClient

      public boolean isFromClient()
      Checks if this event originated from the client side.
      Returns:
      true if the event originated from the client side, false otherwise
    • unregisterListener

      public void unregisterListener()
      Unregisters the event listener currently being invoked.

      This method can only be called from within an event listener. Calling it will remove the current event listener so no further events are passed to it.