The portal also enables the creation of wires between remote portlets that use the Web Services for Remote Portlets (WSRP) v2.0 protocol for event transfer. Remote portlets that have been integrated into the portal and placed on portal pages can be wired, even if they were consumed from different Producers. Remote portlets can also be wired to local standard portlets.
Payload data for remote events is transported as XML content. Therefore, local portlets that want to communicate with remote portlets must either declare event payloads with appropriate XML serialization definitions by using the Java XML Binding framework (JAXB) or process the raw XML strings.
If the remote portlet Producer is also a WebSphere Portal V6.1 portal or another JSR 286–compliant portal, and if local and remote portlets are using the same JAXB definitions, then the correct XML translations happens automatically.
Showing posts with label cooperativeportlet. Show all posts
Showing posts with label cooperativeportlet. Show all posts
Interoperability between events and cooperative portlets
The portal supports data exchange between JSR 168 cooperative portlets and JSR 286 portlets that support events.
But you cannot communicate with IBM Portal API portlet using either JSR 168 or JSR 286 portlets
Take a look at Interoperability between events and cooperative portlets
But you cannot communicate with IBM Portal API portlet using either JSR 168 or JSR 286 portlets
Take a look at Interoperability between events and cooperative portlets
Creating cross page wire
Cross page wires allow your portlet to send data to portlet that is available on different page. THe way it works is when you click on the Action URL in source page it will send event to the target portlet, this will also result in page switch (Page switch is default option but you disable page switch.). Few developers use this mechanism for page navigation.
Before you create cross page wire you will have to enable the event on target portlet to get accept calls globally. You will have to perform few additional steps. Please follow these steps to create cross page wires
Now test your wire by clicking on the action URL in source portlet, it should take you to target page. Comeback and uncheck the switch page checkbox now the event would be sent to target portlet, i.e. target portlets processEvent() method will get executed but user will stay on the source page.
Before you create cross page wire you will have to enable the event on target portlet to get accept calls globally. You will have to perform few additional steps. Please follow these steps to create cross page wires
- Go the Wires tab of the target portlet. If you dont have any other source and target portlets on that page you should see screen like this.
- On this screen it will display all the event targets. Select the target that you want to be invoked globally and check its global checkbox and click ok.
- Now come back to the source page, click on Edit Page Layout and go to Wires tab. Now when you select the source portlet and the event you want to publish, it will populate the Target Page List and now it will have name of the target portlet where you marked a property global, select target page, portlet here. Keep the Switch Page checkbox checked if you want that user to switch from source to target page. Click on add button at the end to actually add the wire.
Now test your wire by clicking on the action URL in source portlet, it should take you to target page. Comeback and uncheck the switch page checkbox now the event would be sent to target portlet, i.e. target portlets processEvent() method will get executed but user will stay on the source page.
Creating wire between portlets on the same page
A wire allows two or more portlets to transfer information so that an action, publishing event, or click in a source portlet automatically triggers an action or event and updates the display in the target portlet. As a result, multiple portlets can be updated simultaneously when information is changed. You can create wires only between cooperative portlets and portlets that define events, that is portlets that have been developed to share information with other portlets
source portlet
The portlet that sends the information to other portlets. You can only select those portlets on the page as source portlets that provide information for other portlets.
target portlet
The portlet that receives the information from the source portlet. Only portlets that can process the information sent by the source portlet are shown.
If you have both source and target portelt on the same page then you create wire between them by clicking on Edit Page Layout and going to Wires tab.

On this tab first open the source portlet combo, it will select all the portlets that can act as source. Select the portlet that you want to create wire for.
It will populate the sending combo to list out all the events that this portlet can pulish, select the appropriate event
At this point if you have the target on the current page it will populate the target page combo with name of the current page. Keep the default and select name of the target portlet in Target Portlet combo.
It will populate the Receiving combo with all the matching events that target portelt can receive. Select the appropriate receiving event.
The Wire Type combo has two choices
Important Note: Creating wire requires customizing the page so user must have minimum "Privileged User" role to create wire. If your Privileged user then the wire that you created would always be private to you. You need role editor and above to create public wire
If you want you can download the sample application that has both source and target portlet from here. Create wire between source and target like this.
source portlet
The portlet that sends the information to other portlets. You can only select those portlets on the page as source portlets that provide information for other portlets.
target portlet
The portlet that receives the information from the source portlet. Only portlets that can process the information sent by the source portlet are shown.
If you have both source and target portelt on the same page then you create wire between them by clicking on Edit Page Layout and going to Wires tab.
On this tab first open the source portlet combo, it will select all the portlets that can act as source. Select the portlet that you want to create wire for.
It will populate the sending combo to list out all the events that this portlet can pulish, select the appropriate event
At this point if you have the target on the current page it will populate the target page combo with name of the current page. Keep the default and select name of the target portlet in Target Portlet combo.
It will populate the Receiving combo with all the matching events that target portelt can receive. Select the appropriate receiving event.
The Wire Type combo has two choices
- Private: You want to create a private wire that wont be available to other users on the page
- Public: You want this wire to be available to every one.
Important Note: Creating wire requires customizing the page so user must have minimum "Privileged User" role to create wire. If your Privileged user then the wire that you created would always be private to you. You need role editor and above to create public wire
If you want you can download the sample application that has both source and target portlet from here. Create wire between source and target like this.
Developing Cooperative Portlets
Starting from JSR 286, the POrtlet Specification defines standard way in which portlet can communicate with each other. This system is called eventing.
You can implement support for eventing by following these steps
You can download the sample code from here
You can implement support for eventing by following these steps
- Define the event that your portlet can either publish or consume in the portlet.xml like this. Add this section to both source and target portlet's portlet.xml
<event-definition>
<description>Sample Event</description>
<name>SampleEvent</name>
<value-type>java.lang.String</value-type>
</event-definition>
In this section we are saying that Sample Event is event of java.lang.String type. - Change your source portlet to define that it can publish Sample Event by adding <supported-publishing-event> element to it.
<portlet>
<portlet-name>SourcePortlet</portlet-name>
<display-name xml:lang="en">SamplePortlet</display-name>
<display-name>SourcePortlet</display-name>
<portlet-class>com.ibm.sampleportlet.SamplePortlet</portlet-class>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<resource-bundle>com.ibm.sampleportlet.nl.SamplePortletResource</resource-bundle>
<portlet-info>
<title>SourcePortlet</title>
<short-title>SourcePortlet</short-title>
<keywords>SourcePortlet</keywords>
</portlet-info>
<supported-publishing-event>
<name>SampleEvent</name>
</supported-publishing-event>
</portlet>
Add your target portlet to add <supported-processing-event> element like this.
<portlet>
<portlet-name>TargetPortlet</portlet-name>
<display-name xml:lang="en">TargetPortlet</display-name>
<display-name>TargetPortlet</display-name>
<portlet-class>com.ibm.sampleportlet.TargetPortlet</portlet-class>
<init-param>
<name>wps.markup</name>
<value>html</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<resource-bundle>com.ibm.sampleportlet.nl.TargetPortletResource</resource-bundle>
<portlet-info>
<title>TargetPortlet</title>
<short-title>TargetPortlet</short-title>
<keywords>TargetPortlet</keywords>
</portlet-info>
<supported-processing-event>
<name>SampleEvent</name>
</supported-processing-event>
</portlet>
Source portlet can publish event either during Action or Event phase. We will support publishing of event in the Action phase by implementing processAction() method like this
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
System.out.println("Inside SamplePortlet.processAction. Sending Event");
java.lang.String sampleObject = new java.lang.String();
response.setEvent("SampleEvent", "EventFromSourcePortlet- processAction");
}- Whenever a event is published the portlet container will pass control to processEvent() method of the target portlet.
public void processEvent(EventRequest request,
EventResponse response) throws
PortletException, java.io.IOException {
System.out.println("Inside TargetPortelt.sampleEvent");
Event sampleEvent = request.getEvent();
System.out.println("Event Name " +sampleEvent.getName().toString());
if(sampleEvent.getName().toString().equals("SampleEvent")) {
Object sampleProcessObject = sampleEvent.getValue();
request.getPortletSession().setAttribute("sampleEvent", sampleEvent.getName());
}
}
The Event object contains both name of the event as well as the pay load. Use it to find out more information about the event.
You can download the sample code from here
Subscribe to:
Posts (Atom)