Blog

Inter-Portlet Communication for Liferay

By  
Marko Grönroos
·
On Jan 4, 2012 3:44:00 PM
·

This year's New Year present goes to all the many people using Vaadin with Liferay. The stable version 1.0.0 of the Vaadin IPC for Liferay add-on was released today. It is very very useful if you want to have two portlets that communicate with each other on the same page.

The normal portal IPC mechanisms that requre reloading the page just won't cut it with Ajax-enabled portlets, as is the case with Vaadin. Liferay includes a JavaScript event API that allows client-side IPC. The Vaadin add-on uses this API, so the other portlets can be any portlets using the same Liferay API, not just Vaadin.

Here's how it works:

The add-on is a simple library that includes one component: LiferayIPC. It is an invisible component that you add in the main window (or layout) of the portlet application. The inter-portlet communication is done between the client-side widgets.

LiferayIPC liferayipc = new LiferayIPC();
layout.addComponent(liferayipc);
...
liferayipc.sendEvent("hello", "This is Data");

To receive an event in other portlets, you define a LiferayIPCEventListener as follows:

liferayipc.addListener("hello", new LiferayIPCEventListener() {
    public void eventReceived(LiferayIPCEvent event) {
        getWindow().showNotification(
           "Received hello: " + event.getData());
    }
});

You can combine this client-side communication method with server-side inter-portlet communication, for example, by using portlet session attributes. You may need to do that for security reasons or if you need to send large amount of data. In such case, you just send a client-side notification that says: "Hey, there's new server-side data available, read it now."

So, go ahead and download it. The add-on package includes this nice demo WAR that you can just deploy in Liferay. It demonstrates how to send and receive inter-portlet events. For documentation, read the new section in the Book of Vaadin. It explains everything. If it doesn't...go and ask in the Vaadin forum.

Marko Grönroos
You haven't yet written a blog author profile for yourself. Go to My Account page to write a short description of yourself.
Other posts by Marko Grönroos