Docs

Documentation versions (currently viewingVaadin 25.1 (pre-release))

Server Push Configuration

Configuration reference for server push in Vaadin Flow applications.

Server push is based on a client-server connection established by the client. The server can then use the connection to send updates to the client. Vaadin uses the Atmosphere framework internally for server push communication.

For practical usage guides and patterns, see Server Push in the Building Apps section.

The @Push Annotation

Enable server push by adding the @Push annotation to the class implementing AppShellConfigurator:

Source code
Java
@Push
public class Application implements AppShellConfigurator {
  ...
}

The annotation supports the following parameters:

Parameter Default Description

value

PushMode.AUTOMATIC

The push mode. See Push Modes.

transport

Transport.WEBSOCKET_XHR

The transport mechanism. See Transport Options.

Push Modes

Server push operates in one of three modes:

Mode Description

PushMode.AUTOMATIC

Changes are pushed to the browser automatically after UI.access() finishes. This is the default mode.

PushMode.MANUAL

Changes are pushed only when you explicitly call UI.push(). Use this for fine-grained control over when updates are sent.

PushMode.DISABLED

Server push is disabled. Use this to explicitly disable push when needed.

Example with manual mode:

Source code
Java
@Push(PushMode.MANUAL)
public class Application implements AppShellConfigurator {
  ...
}

Transport Options

Server push supports three transport mechanisms:

Transport Description

Transport.WEBSOCKET_XHR

Combined WebSockets and XHR. WebSocket is used for server-to-client communication, and XHR for client-to-server communication. This is the default and recommended transport.

Transport.WEBSOCKET

Pure WebSocket connection.

Transport.LONG_POLLING

HTTP long polling. Use this if WebSocket connections are blocked by proxies or firewalls.

Example with long polling:

Source code
Java
@Push(transport = Transport.LONG_POLLING)
public class Application implements AppShellConfigurator {
  ...
}

Servlet Configuration

If you’re manually configuring your servlet, set the async-supported parameter to enable push support.

You can also configure push mode for the entire application in the servlet configuration with the pushMode parameter in the web.xml deployment descriptor, or a corresponding @WebServlet annotation.

On the server side, the push endpoint is mapped to the VAADIN/push path. This mapping is added either under context root, context path, or the first URL mapping (sorted by natural order and ignoring /VAADIN/* and /vaadinServlet/*) of the Vaadin servlet, depending on application deployment configuration. For multiple servlet mappings, configure the pushServletMapping parameter to match the desired mapping.

UI.access() Method

Making changes to a UI from another thread requires locking the user session to prevent conflicts with regular event-driven updates. Use the UI.access() method to safely update the UI from background threads:

Source code
Java
ui.access(() -> statusLabel.setText(statusText));

With manual push mode, call UI.push() explicitly:

Source code
Java
ui.access(() -> {
    statusLabel.setText(statusText);
    ui.push();
});

For detailed patterns and best practices for using UI.access(), including how to avoid memory leaks and flooding, see Pushing UI Updates.

77E22B23-4E6A-4D32-AFCC-2423F633F81D