Tranfer data betwen two portlet vaadin in liferay

I have 2 portlet:A portlet and B portlet. I don’t how can tranfer data betwen A and B
thank for help

There are many other threads already on the forum about inter-portlet communication.

Briefly, you can either:

  • use portlet events or other standard (JSR-286 - Portlet 2.0 spec) portlet IPC methods, or
  • do the communication yourself and then have a
    push or pull
    solution for refreshing the UI of the second portlet

While the first alternative might be slightly simpler (the portlets might not need to know each other etc.), it has one significant drawback: the whole HTML page is reloaded when an event is sent and processed. This is related to the portlet request processing phases in the portlet specification, so you cannot really do much to avoid it.

For the second solution, you have to choose some suitable way for the portlets to get hold of each other and to send messages directly between each other on the server. After that, the push or pull solutions should help get the UI refreshed.

Maybe someone else has a nice example at hand?

Hi Henri
I use PortletSession to tranfer data
But sometimes it has error :
Caused by: java.lang.ClassCastException: com.vaadin.terminal.gwt.server.PortletApplicationContext2 cannot be cast to com.vaadin.terminal.gwt.server.PortletApplicationContext2

this is my code:
if (getContext() instanceof PortletApplicationContext2) {
PortletApplicationContext2 ctx =(PortletApplicationContext2) getContext();
PortletSession session = (PortletSession)ctx.getPortletSession();
session.setAttribute(“name”, “phuongphuongphuongphuong”,PortletSession.APPLICATION_SCOPE);
System.out.println(“share session success”);
ctx.addPortletListener(this, this);
I have configure file vaadin.jar in my project
I use liferay 6.1,vaadin 6.48
what do you think about this problem?

The two instances of PortletApplicationContext2 are using Class instances loaded with different classloaders.

If your portlets are in the same WAR, they should use the same classloader if I remember correctly.

Alternatively (recommended), you should use a shared Vaadin JAR on Liferay for all portlets. As you are using Liferay 6.1 (I assume a custom build, as 6.1 is not yet out), it should already have a Vaadin JAR and resources (/VAADIN/*) already configured so only a reference to vaadin.jar in is needed, and you should remove the Vaadin JAR from your project deployment WAR.

For Liferay versions without Vaadin pre-configured, or to upgrade Vaadin in Liferay, see e.g.
this page

This problem can also be caused by the session context.

When using liferay i noticed that when you redeploy the session loaded the “old version” of the class. Because it is saved in the session context. Normally you can avoid this by adding ?applicationRestart to the url. But in liferay that doesnt work, because the url is not fully shared.

I found a workaround with this in Firefox. Download and install the Webdeveloper toolbar. When you redeploy your war, click cookies > clear session cookies. This may log you out, but its still faster than restarting liferay :slight_smile:

In our experience the the ?restartApplication parameter works with Liferay also. If you have problems with this, please let us know the details.