Docs

Documentation versions (currently viewingVaadin 14)

You are viewing documentation for an older Vaadin version. View latest documentation

Server Push Configuration

When you need to update a UI from another UI, possibly of another user, or from a background thread running in the server, you usually want to have the update show immediately, not when the browser happens to make the next server request. For this purpose, you can use server push that sends the data to the browser immediately. Push is based on a client-server connection, usually a WebSocket connection, that the client establishes and the server can then use to send updates to the client.

This section describes how to configure server push in your application. See Asynchronous Updates for a description on how to use server push from your application code and Creating Collaborative Views for a full multi-user example.

The server-client communication is done by default with a WebSocket connection if the browser and the server support it. If not, Vaadin will fall back to a method supported by the browser. Vaadin Push uses the Atmosphere framework for client-server communication.

Enabling Push in your application

To enable server push, you need to define the push mode either in the deployment descriptor or with the @Push annotation for the main layout.

Push Modes and Transports

You can use server push in two modes: automatic and manual. The automatic mode pushes changes to the browser automatically after access() finishes. With the manual mode, you can do the push explicitly with push(), which allows more flexibility.

Server push can use several transports: WebSockets, long polling, or combined WebSockets+XHR. WebSockets+XHR is the default transport.

The @Push annotation

You can enable server push for the main layout or individual view of an application with the @Push annotation as follows. It defaults to automatic mode (PushMode.AUTOMATIC).

@Push
public class MyLayout extends Div implements RouterLayout {

To enable manual mode, you need to give the PushMode.MANUAL parameter as follows:

@Push(PushMode.MANUAL)
public class MyLayout extends Div implements RouterLayout {

To use the long polling transport, you need to set the transport parameter as Transport.LONG_POLLING as follows:

@Push(transport = Transport.LONG_POLLING)
public class MyLayout extends Div implements RouterLayout {

Servlet Configuration

If you are configuring your servlet manually, you should ensure the async-supported parameter is set.

You can enable server push and define the push mode for an entire application in the servlet configuration with the pushmode parameter for the servlet in the web.xml deployment descriptor or a corresponding @WebServlet annotation.

In addition to this, it is possible to configure the url to use for push requests by setting the pushURL parameter. This is useful for servers that require a predefined URL to push.

E7825FE7-512E-41C1-9C65-7E3B78B429D3