Class BeforeClientResponseAction

java.lang.Object
com.vaadin.flow.component.shared.internal.BeforeClientResponseAction
All Implemented Interfaces:
Serializable

public class BeforeClientResponseAction extends Object implements Serializable
Runs an action for a component once before the next client response.

Use this to defer an update to the end of the round trip, for example when several changes in the same round trip affect the same client-side state and the update should only run once, with the final state. Scheduling the action again before it has run has no effect, and you can cancel a scheduled action.

Compared to registering the action directly with UI.beforeClientResponse(com.vaadin.flow.component.Component, com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.internal.ExecutionContext>), the action also runs if the component is detached and attached again before the response, also to a different UI.

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

Since:
25.4
See Also:
  • Constructor Details

    • BeforeClientResponseAction

      public BeforeClientResponseAction(Component component, SerializableRunnable action)
      Creates a new action for the given component. The action is not scheduled until you call schedule().

      If the action is a lambda or a method reference, do not store it in another field and do not capture it in another lambda. Otherwise the component can fail to deserialize.

      Parameters:
      component - the component whose client response the action runs before, not null
      action - the action to run, not null
  • Method Details

    • schedule

      public void schedule()
      Schedules the action to run before the next client response while the component is attached. If the component is not attached, the action runs before the first response after the component has been attached. Does nothing if the action is already scheduled.

      The action only runs while the component is attached.

    • cancel

      public void cancel()
      Cancels the scheduled action. Does nothing if the action is not scheduled.