Showing posts with label IPC. Show all posts
Showing posts with label IPC. Show all posts

Sunday, October 18, 2009

Inter Portlet Communication between Pageflows in Weblogic Portal

Well, Weblogic documentaions are too good, but I had to put considerable effort to make it work. To explain the inter portlet communication between two pageflow let's take this use case.

1. Pageflow PublisherController will publish a custom event.
2. Published custom event will carry a payload.
3. This custom event will be consumed by ConsumerController pageflow.
4. It will extract the payload from the event.

Publisher pageflow

@Jpf.Controller
public class PublisherController extends PageFlowController {
@Jpf.Action(forwards = { @Jpf.Forward(name = "success", path = "index.jsp") })
public Forward publish() {
PortletBackingContext ctx = PortletBackingContext.getPortletBackingContext(getRequest());
ctx.fireCustomEvent("myCustomEvent", "I am from Publisher pageflow.");
return new Forward("success");
}
}


Backing file

public class EventBacking extends AbstractJspBacking {
public void captureEvent(HttpServletRequest request, HttpServletResponse response, Event event) {
CustomEvent custEvent = (CustomEvent)event;
Serializable payload = (Serializable)custEvent.getPayload();
PortletBackingContext ctx = PortletBackingContext.getPortletBackingContext(request));
String ipcPayloadAttrName = ctx.getInstanceId() + "_ipcPayload";
HttpSession session = request.getSession();
session.setAttribute(ipcPayloadAttrName, payload);
}
}


Consumer pageflow

@Jpf.Controller()
public class ConsumerController extends PageFlowController {
@Jpf.Action(forwards = { @Jpf.Forward(name = "default", path = "index.jsp") })
public Forward consume() {
PortletBackingContext ctx = PortletBackingContext.getPortletBackingContext(getRequest());
String message = (String)getSession().getAttribute(ctx.getInstanceId() + "_ipcPayload");
getSession().removeAttribute(ctx.getInstanceId() + "_ipcPayload");
return new Forward("default");
}
}

To be contd...