/ VAADIN

Server-client push with Vaadin

I’m more and more comitted into Vaadin since I see so many advantages to this solution. This time, I’ve investigated how to push server data to the client.

Vaadin is a general purpose framework that is wise enough not to force you to code in one way or another. Many features are available in the core distribution but many more are available in the add-ons directory. One such add-on let you add push feature to your simple application. This add-on is based on ICEPush technologies and is aptly named ICEPush add-on.

ICEPush is a brand of technology usable with both Java and JavaScript that uses long polling in order to achieve push and as such does not need port opening (save the one the standard HTTP stream uses, of course). The ICEPush Vaadin add-on integrates ICEPush into your Vaadin application in a very simple way, so that only so much steps are needed in order to develop a full-fledged application with push features.

Set-up ICEPush add-on

Once you’ve created your Vaadin project (and application), add the ICEPush libraries to your project. If you use Maven, just add the following snippet to your POM:

<dependency>
   <groupId>org.vaadin.addons</groupId>
   <artifactId>icepush</artifactId>
   <version>0.2.0</version>
</dependency>
<repository>
   <id>vaadin-addons</id>
   <url>http://maven.vaadin.com/vaadin-addons</url>
</repository>

If not, just download the ZIP available in the directory. Beware that all JAR inside should be copied to your WEB-INF/lib. Even though 2 of them look alike, one is the ICEPush JAR, the other the integration layer on Vaadin.

If you use the Vaadin plugin with your IDE, and it asks you to recompile your widgetset, just click yes and be done with it.

Use the right servlet

Replace the default servlet configured in your web.xml (probably com.vaadin.terminal.gwt.server.ApplicationServlet) with org.vaadin.artur.icepush.ICEPushServlet.

Add the ICEPush object to your window

In order to use push technology, you’ll have to add a new ICEPush object to the window in use, like so:

public class PushApplication extends Application {

  private ICEPush push = new ICEPush();

  @Override
  public void init() {
    Window mainWindow = new Window("Push Application Example");
    mainWindow.addComponent(push);
  }
}

Now, each time you nee to update the window, just call push.push() and it’s done!

This method call will update the client’s window with the update you made. Vaadin will do true AJAX in that it won’t reload the page, just update the view with the changes.

As usual, you’ll find the source of this article here, in Eclipse format.

Nicolas Fränkel

Nicolas Fränkel

Nicolas Fränkel is a technologist focusing on cloud-native technologies, DevOps, CI/CD pipelines, and system observability. His focus revolves around creating technical content, delivering talks, and engaging with developer communities to promote the adoption of modern software practices. With a strong background in software, he has worked extensively with the JVM, applying his expertise across various industries. In addition to his technical work, he is the author of several books and regularly shares insights through his blog and open-source contributions.

Read More
Server-client push with Vaadin
Share this