Hi,
I’m trying to get a simple demonstration of inter-portlet communication(using JSR-286) working in Liferay. I have two portlets, each in its own separate Eclipse project, and export as its own .war file. The idea is for one portlet(PortletSend) to send an event that another portlet(PortletReceive) receives and handles.
My problem is that PortletReceive doesn’t receive the event(the handleEventRequest method is never even called).
I’ve basically pulled this code from here:
http://demo.vaadin.com/docs/example-source/com/vaadin/demo/portlet/
PortletSend(I’m checking to see if any of the request handler methods are called here as well)
package com.example.portletsend;
import java.util.Date;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.EventRequest;
import javax.portlet.EventResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.xml.namespace.QName;
import com.vaadin.terminal.gwt.server.PortletApplicationContext2;
import com.vaadin.Application;
import com.vaadin.ui.*;
import com.vaadin.ui.Button.ClickEvent;
public class PortletsendApplication extends com.vaadin.Application
implements PortletApplicationContext2.PortletListener {
private int numClicks = 0;
private Label greeting;
private Label clicksLabel;
private Label errorLabel;
private Label infoLabel;
private Label eventLabel;
@Override
public void init() {
if (getContext() instanceof PortletApplicationContext2) {
PortletApplicationContext2 ctx = (PortletApplicationContext2) getContext();
ctx.addPortletListener(this, this);
}
Window mainWindow = new Window("PortletSend");
mainWindow.addComponent(new Label("PortletSend - sends event"));
setMainWindow(mainWindow);
errorLabel = new Label();
mainWindow.addComponent(errorLabel);
infoLabel = new Label();
infoLabel.setCaption("Info Label:");
mainWindow.addComponent(infoLabel);
eventLabel = new Label();
eventLabel.setCaption("Event Label:");
mainWindow.addComponent(eventLabel);
Button button = new Button("Say hello");
button.addListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
try {
// create an action URL and activate it to be able to create and
// send an event
if (getContext() instanceof PortletApplicationContext2) {
PortletApplicationContext2 ctx = (PortletApplicationContext2) getContext();
numClicks++;
clicksLabel.setCaption("There have been " + numClicks
+ " events");
// set HelloState shared render parameter before sending the
// event
// note that this is inefficient as each call creates an
// action
ctx.setSharedRenderParameter(getMainWindow(), "HelloState",
"" + numClicks);
[b]
ctx.sendPortletEvent(getMainWindow(), new QName(
"http://vaadin.com/hello", "FromVaadin"),
"Greetings from PortletSend");
[/b]
}
errorLabel.setCaption("event sent successfully - "+new Date());
}
catch (Exception ex) {
errorLabel.setCaption("error sending event - "+new Date());
}
}
});
mainWindow.addComponent(button);
greeting = new Label();
mainWindow.addComponent(greeting);
clicksLabel = new Label();
mainWindow.addComponent(clicksLabel);
}
public void handleActionRequest(ActionRequest request,
ActionResponse response, Window window) {
infoLabel.setValue("handleActionRequest was called");
}
public void handleResourceRequest(ResourceRequest request,
ResourceResponse response, Window window) {
infoLabel.setValue("handleResourceRequest was called");
}
public void handleRenderRequest(RenderRequest request,
RenderResponse response, Window window) {
infoLabel.setValue("handleRenderRequest was called");
}
public void handleEventRequest(EventRequest request,
EventResponse response, Window window) {
infoLabel.setValue("handleEventRequest was called");
eventLabel.setValue("handleEventRequest was called");
}
}
Portlet Receive:
package com.example.portletreceive;
import java.util.Date;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.EventRequest;
import javax.portlet.EventResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.xml.namespace.QName;
import com.vaadin.terminal.gwt.server.PortletApplicationContext2;
import com.vaadin.Application;
import com.vaadin.ui.*;
import com.vaadin.ui.Button.ClickEvent;
public class PortletreceiveApplication extends com.vaadin.Application
implements PortletApplicationContext2.PortletListener {
private Label greeting;
private Label infoLabel;
@Override
public void init() {
if (getContext() instanceof PortletApplicationContext2) {
PortletApplicationContext2 ctx = (PortletApplicationContext2) getContext();
ctx.addPortletListener(this, this);
}
Window mainWindow = new Window("PortletRecieve");
mainWindow.addComponent(new Label("PortletReceive - receives event from PortletSend"));
infoLabel = new Label("Info Label");
mainWindow.addComponent(infoLabel);
greeting = new Label();
mainWindow.addComponent(greeting);
setMainWindow(mainWindow);
}
public void handleRenderRequest(RenderRequest request,
RenderResponse response, Window window) {
infoLabel.setCaption("handleRenderRequest was called");
}
public void handleActionRequest(ActionRequest request,
ActionResponse response, Window window) {
infoLabel.setCaption("handleActionRequest was called");
}
public void handleEventRequest(EventRequest request,
EventResponse response, Window window) {
infoLabel.setCaption("handleEventRequest was called");
// if (request.getEvent().getName().equals("FromPortletSend")) {
[b]
greeting.setCaption("Received: " + request.getEvent().getValue()
+ " at " + new Date());
[/b]
// response.setEvent(
// new QName("http://www.vaadin.com/hello", "Reply"),
// "Reply from HelloWorld");
// }
// else if (request.getEvent().getName().equals("ReplyToVaadin")) {
// greeting.setCaption("Received reply: "
// + request.getEvent().getValue() + " at " + new Date());
// }
}
public void handleResourceRequest(ResourceRequest request,
ResourceResponse response, Window window) {
infoLabel.setCaption("handleResourceRequest was called");
}
}
I’ve also put these event definitions into the portlet.xml file for each portlet:
<supported-processing-event>
<qname xmlns:vaadin="http://vaadin.com/hello">vaadin:Hello</qname>
</supported-processing-event>
<supported-processing-event>
<qname xmlns:vaadin="http://vaadin.com/hello">vaadin:ReplyToVaadin</qname>
</supported-processing-event>
<supported-publishing-event>
<qname xmlns:vaadin="http://vaadin.com/hello">vaadin:Reply</qname>
</supported-publishing-event>
<supported-publishing-event>
<qname xmlns:vaadin="http://vaadin.com/hello">vaadin:FromVaadin</qname>
</supported-publishing-event>
<supported-public-render-parameter>HelloState</supported-public-render-parameter>
Thanks in advance for your help.