Interportlet communication in Weblogic Portal 10.3.2 using WLP Events and Shared Parameters

The problem : How to make two portlets communicate with each other, and make one portlet, listen to another portlet event?

Introduction

The need to develop portlets that communicate with each others. When I developed this first, I used shared parameters (even cache attributes) and JavaScript methods to invoke notify a portlet with an event. But this method is a very customized solution that can’t be re-used easily. It needs big effort maintenance also.

WLP Shared Parameters

As we are talking about Weblogic Portlets, We can define shared parameters that the portlet instance can read/write. These parameters can be the global variable that is shared between multiple portlets. Shard parameters are defined in the properties of the portlet sharing them. Define parameter ID and qualified name. Check next figure

Figure 1 : Weblogic Portlet shared parameters

WLP Portlet Custom Events

Weblogic Portlets can fire custom events and handle different types of events (built-in or custom events). Weblogic Portlets can handle events by defining them in the portlet properties, add the Event handler type (Custom), then add an action to be performed as “Invoke BackingFile Method” and enter the name of the method (Check next figure). This method should have this signature :

public void handlePortalEvent(HttpServletRequest request,
HttpServletResponse response, Event event)

Figure 2 : Weblogic Portlet Events Handlers

WLP Fire Custom Events

After defining shared parameters in both portlets that need to communicate with each other, we need to fire the event from one portlet, notifying the other portlet of the event. We here demonstrate how to fire custom event in Weblogic Portlet using Ajax post, without the need of post-back the page.

  1. First, include the taglib “render in your JSP : <%@ taglib uri="http://www.bea.com/servers/portal/tags/netuix/render" prefix="render"%>
  2. Define a URL to the page firing the custom event using the following render:customEventUrl Tag : <render:customEventUrl eventName="customEvent" var="customEventUrl" forcedAmpForm="false">
    </render:customEventUrl>
  3. Add the following Javascript code to your portlet JSP to be performed on some button click or whatever client side action :

<script language="javascript">
var fireEvent = function() {
var eventParamValue = document.getElementById("eventParam").value;
var paXhr = new bea.wlp.disc.io.XMLHttpRequest();
var url="<%=customEventUrl%>";
url += "&eventParam="+eventParamValue;
paXhr.open("POST", url);
paXhr.send();
}
</script>

Then, the event handler method defined in the BackingFile of the portlet, can handle the event.

Set the shared parameters

Still the other portlet can’t find the event parameter in the shared parameters. Then, we need to handle the post back of the page, in the sending portlet, by overriding the method named “handlePostbackData” and make it set the shared parameter, to enable the other portlet when handling the event, to read the shared parameter. The method should do the following:

@Override
public boolean handlePostbackData(HttpServletRequest request,
HttpServletResponse response) {

String eventSharedParam = request.getParameter(“eventParam”);

PortletBackingContext ctx = PortletBackingContext.getPortletBackingContext(request);

ctx.setSharedParameterValue(“sharedParamName”, eventSharedParam);

return super.handlePostbackData(request, response);
}

Conclusion

WLP provides predefined events handling, custom events handling. Also provides the Ajax way to fire these events.

WLP provides shared parameters between portlets which could be useful to share common variables such as portal language.

Advertisements

3 thoughts on “Interportlet communication in Weblogic Portal 10.3.2 using WLP Events and Shared Parameters

  1. Hi Ahmed,
    Have you tried using Shared Parameters across WSRP?

    1. No I didn’t try it, did you face problems with it?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close