July 2006

« February 2007 | Main | March 2006 »

Handling events for a WSRP portlet locally

Monday, July 17, 2006

At first glance, it does not appear possible to add IPC events in a proxy portlet where the event would be handled by the local consumer portal. However, with a little hand editing and knowledge it is quite easy to do this.

A WSRP portlet on the consumer side is referred to as a proxy portlet since it simply proxies the content from the producer. When you create a new proxy portlet on the consumer it automatically inherits the event handlers from the producer portlet. Opening the event dialog for a proxy portlet shows these inherited events, however you will notice that the event editing buttons are missing from the dialog. This prevents you from editing remote events, which is a good thing, but also prevents you from adding your own events, which is a bad thing in my opinion.

Not being able to add events handlers or actions to the proxy portlet is annoying because you occasionally want to add an action or handler to the proxy portlet that the original producer may not have considered. For example, you may want the proxy portlet to activate it's page when a particular event occurs.

Fortunately, while the dialog does not allow you to add event handlers it is quite easy to do so by simply hand editing the proxy portlet XML file. If you view the XML for a proxy portlet that has events, you should see an event handling stanza as follows:

<netuix:handleEvent event="testEvent" eventLabel="handleCustomEvent1" filterable="true"
 fromSelfInstanceOnly="false" onlyIfDisplayed="false" sourceDefinitionWildcard="any">
    <netuix:dispatchToRemotePortlet/>
</netuix:handleEvent>

The key here is the netuix:dispatchToRemotePortlet tag which tells Portal to propagate events to the producer. To handle the event locally, simply create a whole new netuix:handleEvent block and append it after the initial block in the proxy portlet file. For example:

<netuix:handleEvent event="testEvent" eventLabel="handleCustomEvent1" filterable="true"
 fromSelfInstanceOnly="false" onlyIfDisplayed="false" sourceDefinitionWildcard="any">
    <netuix:dispatchToRemotePortlet/>
</netuix:handleEvent>
<netuix:handleEvent event="testEvent" eventLabel="handleCustomEvent2" filterable="true"
 fromSelfInstanceOnly="false" onlyIfDisplayed="false" sourceDefinitionWildcard="any">
    <netuix:activatePage/>
</netuix:handleEvent>

This will cause the event to be handled locally as well as remotely and enables you to manage events in a proxy portlet that are specific to the consumer and do not need to be propagated to the producer portal. BTW, if you cut and paste the remote event handler to make a local event handler, make sure to change the eventLabel to something unique.

If you are unsure of what XML to paste in for a particular event or action, create a temporary local portlet and edit it with the dialog accordingly. Once you have created your event and action, open the temporary portlet as XML and copy and paste the event code to the proxy portlet.

Posted by Gerald Nunn at 4:02 PM | Categories: | Permalink |