Interportlet Communication (IPC) and JSF: how to use SUN's api?

Ok, FacesPortlet is derived from GenericPortlet.

In SUN-description is stated that processAction() must send the event.

But how can I access processAction() since it's not provided within JSF since the portlet-bridge handles this class?

In short: Is there a way to use SUN's interportlet communication within JSF?

Thanx in advance

Jochen

[376 byte] By [DschayTia] at [2007-11-27 4:47:09]
# 1
Check this article http://developers.sun.com/portalserver/reference/techart/ipc.html
dgothea at 2007-7-12 9:59:49 > top of Java-index,Web & Directory Servers,Portal Servers...
# 2
Thanx for you answer. But this article deals only with IPC with session help.But I want to have IPC with SUN's API ... and JSF!!!Any clues?
DschayTia at 2007-7-12 9:59:50 > top of Java-index,Web & Directory Servers,Portal Servers...
# 3
if you read the full article, it uses the sun ipc event interface. That is the correct way to do it (even though the tutorial provided by the article is a bit screwy and I was never able to get it to work fully).
jbjonesjra at 2007-7-12 9:59:50 > top of Java-index,Web & Directory Servers,Portal Servers...
# 4

You are right: the article deals with IPC using SUN's API.

So I have put the ZIP-file, which was linked in the article, and have done the following:

- Deploying the war-file (included in the zip) in the portal server: Success, it works.

- Building a NetBeans project using the sources (java, xml, jsp, ...) of the ZIP file. After having some problems I deployed it also with success!

But only the listener (= describer) is handled in the example. Nothing about how to program the sender of an event.

And by the way: the example is hardly to understand because the ui-taglibs of SUN were used instead the ones JSF offers.

At least the question "How to use JSF within IPC" could be solved for the subscriber side: Make your own class e.g. EventHandlerPortlet, wich is derived from FacesPortlet und annouce this one as portlet-class within portlet.xml:

<portlet-class>ipcportlet.EventHandlerPortlet</portlet-class>

So my question now is: How do I implement the event generator within a JSF portlet?

DschayTia at 2007-7-12 9:59:50 > top of Java-index,Web & Directory Servers,Portal Servers...
# 5

Hmm, sending events is handled much the same way. The issue comes up in that: If you search around the javadocs for the EventHandler and associated objects, you can figure out sending without much trouble (again, much the same as receiving, is just as easier as calling the object and sending the event).

An event can only be sent doing the processAction stage of the portlet lifecycle, which the SUN JSFportlet bridge does not expose to the application. I am searching around, I have some sample source which showed sending an event, I will see if I can track it down. However, I had hoped to see some help from SUN on this, as I spent about a month trying to get the SUN IPC to work with the JSF bridge, and was not able to get it working. they provide a step by step tutorial that I or 3 coworkers on different development machines could get it to work.

jbjonesjra at 2007-7-12 9:59:50 > top of Java-index,Web & Directory Servers,Portal Servers...
# 6

You can use PortletEventBroker class of IPC to send events. You need to extend FacesPortlet and override processAction. ..something like this..

Event generation:

EventGeneratingPortlet extends FacesPortlet {

public void processAction(ActionRequest request, ActionResponse actionResponse)

throws PortletException, IOException {

super.processAction();

PortletEventBroker peb = new PortletEventBroker(request);

PortletEvent pe = peb.createEvent(...);

...

pe.setEventData(..);

pe.fire();

}

}

And in listener..

EventConsumingPortlet extends FacesPortlet implements PortletEventListener {

public void handleEvent(EventRequest ereq, EventResponse eres) {

// Acquire the FacesContext instance for this request

FacesContext context =

getFacesContextFactory().getFacesContext

(portletConfig.getPortletContext(),

request, response, lifecycle);

//Get the event name

String eventName = ereq.getEventName();

//process the event..

}

}

dgothea at 2007-7-12 9:59:50 > top of Java-index,Web & Directory Servers,Portal Servers...
# 7

Unfortunately, the tutorial uses Java Studio Creator, which does not provide direct access to the Faces Portlet class, but instead, to the AbstractPageBean class (which in turn extends facesportlet itself). [http://developers.sun.com/docs/jscreator/apis/jsfcl/com/sun/jsfcl/app/Abstract PageBean.html]

Because of that, this usurps many of the methods within FacesPortlet. How will that factor into the equation?

jbjonesjra at 2007-7-12 9:59:50 > top of Java-index,Web & Directory Servers,Portal Servers...
# 8
Actually, I take that back... Abstract PageBean is NOT extended from FacesPortlet, so there is no method of connecting such classes as processAction to the bean provided.
jbjonesjra at 2007-7-12 9:59:50 > top of Java-index,Web & Directory Servers,Portal Servers...
# 9

I got the solution: IPC mixed up with JSF when sending an event:

Within a JSP-file the method send() is called.

<h:commandButton action="#{SendEvent.send}" value="send Event"></h:commandButton>

The class SendEvent looks like this:

import javax.faces.context.ExternalContext;

import javax.faces.context.FacesContext;

import com.sun.portal.portletappengine.ipc.PortletEvent;

import com.sun.portal.portletappengine.ipc.PortletEventBroker;

import com.sun.portal.portletappengine.ipc.EventNotRegisteredException;

import javax.portlet.ActionRequest;

import javax.portlet.PortletRequest;

public class SendEvent {

public void send() {

try {

System.err.println("-- send -- ");

FacesContext fc FacesContext.getCurrentInstance();

ExternalContext ec = fc.getExternalContext();

Object request = ec.getRequest();

if (!(request instanceof PortletRequest)) {

throw new Exception("Application is no Portlet!!!");

}

PortletRequest pr = (PortletRequest)request;

ActionRequest request = (ActionRequest)(pr);

PortletEventBroker peb = new PortletEventBroker(request);

try {

peb.createEvent("priceChanged");

PortletEvent pe = peb.createEvent("priceChanged");

String sEventData = "300";

pe.setEventData(sEventData);

pe.fire();

PortletEvent pe2 = peb.createEvent("priceChanged2");

pe.setEventData("700");

pe.fire();

PortletEvent pe3 = peb.createEvent("priceChanged3");

pe3.setEventData("800");

pe3.fire();

}

catch (EventNotRegisteredException enre) {

System.err.println("Error enre = " + enre);

}

catch (Exception ex2) {

System.err.println("Error ex. = " + ex2);

ex2.printStackTrace();

}

}

catch(Exception ex) {

System.err.println("Error -- ex. = " + ex);

}

}

}

Keep in mind to define the events in sun-portlet.xml

<?xml version="1.0" encoding="UTF-8"?>

<portlet-app-extension xmlns="http://www.sun.com/software/xml/ns/portal_server"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:sunportal="http://www.sun.com/software/xml/ns/portal_server"

xsi:noNamespaceSchemaLocation="http://www.sun.com/software/xml/ns/portal_server" version="1.0">

<portlet>

<portlet-name>IPCPortletName</portlet-name>

<deployment-extension>

<extension-element>

<session-enabled>0</session-enabled>

</extension-element>

</deployment-extension>

<events>

<generates-event>priceChanged</generates-event>

<generates-event>priceChanged2</generates-event>

<generates-event>priceChanged3</generates-event>

</events>

</portlet>

</portlet-app-extension>

You can include this Portlet in the developer sample, Interportlet communication.

When pressing 'send Event' the Portlets 'Consideration', 'List' and 'Decision' will get

their values 300, 700 and 800.

By the way: Thanx to everyone who tried to help me.

DschayTia at 2007-7-12 9:59:50 > top of Java-index,Web & Directory Servers,Portal Servers...