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.
Note: 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.
To go further:
- ICEPush technology site
- ICEPush add-on page on Vaadin’s directory
- A truly mystifying demo (as well as a real use case)

thank you for the nice tutorial. maybe you can also leave a note about IcePush in Vaadin using Portlets (ApplicationPortlet rather than ApplicationServlet)?
@Patrick
To be true, I’m was not (and am still) not very convinced with portlets, so I didn’t investigate the matter further. If you are interested, my advice is to look at the source of Vaadin’s ApplicationPortlet and ICEPushServlet and create a mix of the two. I am interested in the results, by the way. Good luck!
Two things to note though: 1) when updating in the background, you should do synchronize(app){} so that you don’t end up changing things while the user interactions are also changing things. Then you can do the push() call (just after the synchronization end)
2) You have to be careful not to call push() in the constructor for your Vaadin component.
When I integrate the ICEPush Dependency in my pom.xml like you wrote I’m running in problems when it comes to compiling the widgetset. The exact error is as follows:
——————————
Loading inherited module ‘org.icepush.gwt.ICEpush’
[ERROR] Unable to find ‘org/icepush/gwt/ICEpush.gwt.xml’ on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
——————————
That error belongs to the missing icepush-gwt.jar which is not included in the dependency.
Is there anothersolution to fix this than uploading to to my own nexus server?
Sadly, no. Since the ICEPush JAR is not available in any public repo (yet?), manually putting it in your own enterprise repo is the only way.