LiferayIPC sharing session attributes problem

Hello Everybody,
I’m trying to share session attributes between two portals in separate wars, and i have problem with this. First of all I’m using vaadin 6.7.6, Liferay 6.1.0, and vaadin icp for liferay 0.9.1.
So my FirstPortlet packed in first *.war ha sthe following code:


public class FirstPortletApplication extends Application {
	
	private static final long serialVersionUID = -4806444519469629099L;
	private MyButton myButton;
	private LiferayIPC liferayIPC;
	private Window mainWindow;
	private VerticalLayout vLayout = new VerticalLayout();
	
	@Override
	public void init() {
		mainWindow = new Window("FirstPortlet Application");
		Label label = new Label("Hello Vaadin user");
		liferayIPC = new LiferayIPC();
		myButton = new MyButton(liferayIPC, this);
		vLayout.addComponent(label);
		vLayout.addComponent(myButton.getButton());
		vLayout.addComponent(liferayIPC);
	    mainWindow.addComponent(vLayout);	
		setMainWindow(mainWindow);
	}

}

and MyButton class code is:


public class MyButton implements Button.ClickListener {

	private static final long serialVersionUID = 2263127718676221746L;
	private Button myButton;
	private final LiferayIPC liferayIPC;
	private final FirstPortletApplication app;
	
	public MyButton(LiferayIPC liferayIPC, FirstPortletApplication app) {
		this.liferayIPC = liferayIPC;
		this.app = app;
		myButton = new Button("Send Event");
		myButton.addListener((Button.ClickListener) this);
	}
	
	public Button getButton() {
		return myButton;
	}
	
	@Override
	public void buttonClick(ClickEvent event) {
		Button button = event.getButton();
		if (button == myButton) {
			System.out.println("Event sending!");
			String key = "LIFERAY_SHARED_data";
		    String send = "TestDATA";
		    PortletSession session = ((PortletApplicationContext2)app.getContext()).getPortletSession();
		    System.out.println("SessionID:" + session.getId());
		    System.out.println("Attribute added: key: " + key + " value: " + send);
			session.setAttribute( key,  send, PortletSession.APPLICATION_SCOPE);
			
			
		        
			Enumeration attr = session.getAttributeNames();
			System.out.println("Session attributes:");
            while (attr.hasMoreElements()) {
                System.out.println("Get attr:" + attr.nextElement());
            }
			liferayIPC.sendEvent( "MyButtonEvent", key);
		}
		
	}

	
}

The second portled in other war has the code:


public class SecondPortletApplication extends Application {
	
	private static final long serialVersionUID = 1588684714580268223L;
	private LiferayIPC liferayIPC;
	private Window mainWindow;
	private VerticalLayout vLayout = new VerticalLayout();
	private Label label;
	
	@Override
	public void init() {
		mainWindow = new Window("SecondPortlet Application");
		label = new Label("Hello Vaadin user");
		vLayout.addComponent(label);
		liferayIPC = new LiferayIPC();
	    liferayIPC.addListener("MyButtonEvent", new LiferayIPCEventListener() {
		    public void eventReceived(LiferayIPCEvent event) {
		        System.out.println("Event receiving");
		        String key = event.getData();
		        System.out.println("Event key:" + key);
		        
		        PortletSession session = ((PortletApplicationContext2)getContext()).getPortletSession();
		        String testData = (String)session.getAttribute( key );
		        System.out.println("SessionID:" + session.getId());
		        Enumeration attr = session.getAttributeNames();
		        while (attr.hasMoreElements()) {
		            System.out.println("Get attr:" + attr.nextElement());
		        }
		        System.out.println(testData);   
		        
		    }
		});
	    vLayout.addComponent(liferayIPC);
		mainWindow.addComponent(vLayout);
		setMainWindow(mainWindow);
	}


}

And of course I put false into liferay-portlet.xml file.

So everything seems to be fine, and done like in Vaadin Book or many other examples I found on the internet.

But the result of clicking o “Send Event” button is:


Event sending!
SessionID:06C23A1D1FF45212395A5C185E2EBA4F
Attribute added: key: LIFERAY_SHARED_data value: TestDATA
Session attributes:
Get attr:Vaadin-Security-Key
Get attr:com.vaadin.terminal.gwt.server.PortletApplicationContext2
Event receiving
Event key:LIFERAY_SHARED_data
SessionID:06C23A1D1FF45212395A5C185E2EBA4F
Get attr:Vaadin-Security-Key
Get attr:com.vaadin.terminal.gwt.server.PortletApplicationContext2
null

So looks like attribute LIFERAY_SHARED_data is not stored in session, and is not shared with second portlet.
When I changed for testing scope for PORTLET_SCOPE, the attribute was stored in session, but still it wasn’t shared with second portlet (as expected in this case).
So my question is: am I doing something wrong or it’s this framework/add-on version bug or something else ?

Hi,

I don’t think it can be an add-on bug as the event is received in the other portlet, and that’s all the add-on does. And it’s probably not a Vaadin issue either…probably. It must be a problem with the scope of the attributes in the different WARs. Well, even the session IDs are the same in your test, so the portlets are using the portal session as they should…

It’s really odd that it doesn’t even write the attribute value. Ahh… Do you have the “private” setting true or false? The portal session is read-only unless the setting is false. At least so I understand from
this article about session sharing in Liferay
.

To Everybody who has the same problem. I sloved it.
I checked PortalSession javadoc, and what I found is:
getAttributeNames() - returns session attribute names but only from PORTLET_SCOPE, that’s why my APPLICATION_SCOPE attribute wasn’t visible.
And the second think: to get attribute value which is in APPLICATION_SCOPE, we have to write it explicityly by using method:
session.getAttribute(key, PortletSession.APPLICATION_SCOPE)
and it works.

So the example from book of vaadin (secion13.10) is not correct.

Tomasz Solution worked for me too.

Thanks