This Example, Using public render parameter, portlet communication between two portlets in Portet Aggregator Application is done.
MyPortletcoord.war (Aggregator Application)
Context Path: myportletcoord
<%@ taglib uri="http://ibm.com/portlet/aggregation" prefix="portlet" %>
<%@ page isELIgnored ="false"%>
<!-- define portal scope for public render parameters -->
<portlet:scope>
<portlet:portlet context="/myjsrsender" portletname="MyJSR286Sender" windowId="stephan"/>
<portlet:portlet context="/myjsrreceiver" portletname="MyJSR286Receiver" windowId="birga"/>
</portlet:scope>
<portlet:init portletURLPrefix="/myportletcoord/portal/">
<!-- insert your portlets here, wrapped with your html markup -->
...
<portlet:insert url="myjsrsender/MyJSR286Sender" windowId="stephan" titleVar="portlettitle_1"/>
...
<portlet:insert url="myjsrreceiver/MyJSR286Receiver" windowId="birga" titleVar="portlettitle_2"/>
...
</portlet:init>
MyJSR286Sender.war (Sender Application)
Name of Portlet : MyJSR286Sender
Context path: myjsrsender
MyJSR286Sender.java
package com.ibm.myjsr286;
import java.io.*;
import javax.portlet.*;
public class MyJSR286Portlet extends GenericPortlet {
.........
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
response.setRenderParameter("myname", request.getParameter("myname"));
}
}
MyJSR286PortletView.jsp
<%@page session="false" contentType="text/html" pageEncoding="ISO-8859-1" import="java.util.*,javax.portlet.*,com.ibm.myjsr286.*" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:defineObjects/>
Enter your Name<BR>
<form action='<portlet:actionURL/>'>
<input type="text" name="myname"/>
<input type="password" name="password"/>
<input type="submit" name="submit" value="submit"/>
</form>
portlet.xml
<portlet>
MyJSR286Receiver.war (Receiver Application)
Name of Portlet : MyJSR286Receiver
Context path: myjsrreceiver
MyJSR286ReceiverPortletView.jsp
<%@page session="false" contentType="text/html" pageEncoding="ISO-8859-1" import="java.util.*,javax.portlet.*,com.ibm.myjsr286receiver.*" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<DIV style="margin: 6px">
<H3 style="margin-bottom: 3px">Welcome! ${param.myname}</H3>
</DIV>
portlet.xml
<portlet>
ScreenShot
Click here to download the sample code.
MyPortletcoord.war (Aggregator Application)
Context Path: myportletcoord
<%@ taglib uri="http://ibm.com/portlet/aggregation" prefix="portlet" %>
<%@ page isELIgnored ="false"%>
<!-- define portal scope for public render parameters -->
<portlet:scope>
<portlet:portlet context="/myjsrsender" portletname="MyJSR286Sender" windowId="stephan"/>
<portlet:portlet context="/myjsrreceiver" portletname="MyJSR286Receiver" windowId="birga"/>
</portlet:scope>
<portlet:init portletURLPrefix="/myportletcoord/portal/">
<!-- insert your portlets here, wrapped with your html markup -->
...
<portlet:insert url="myjsrsender/MyJSR286Sender" windowId="stephan" titleVar="portlettitle_1"/>
...
<portlet:insert url="myjsrreceiver/MyJSR286Receiver" windowId="birga" titleVar="portlettitle_2"/>
...
</portlet:init>
MyJSR286Sender.war (Sender Application)
Name of Portlet : MyJSR286Sender
Context path: myjsrsender
MyJSR286Sender.java
package com.ibm.myjsr286;
import java.io.*;
import javax.portlet.*;
public class MyJSR286Portlet extends GenericPortlet {
.........
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
response.setRenderParameter("myname", request.getParameter("myname"));
}
}
MyJSR286PortletView.jsp
<%@page session="false" contentType="text/html" pageEncoding="ISO-8859-1" import="java.util.*,javax.portlet.*,com.ibm.myjsr286.*" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:defineObjects/>
Enter your Name<BR>
<form action='<portlet:actionURL/>'>
<input type="text" name="myname"/>
<input type="password" name="password"/>
<input type="submit" name="submit" value="submit"/>
</form>
portlet.xml
<portlet>
<portlet-name>MyJSR286Sender</portlet-name>
...
<supported-public-render-parameter>foo</supported-public-render-parameter>
</portlet>
<public-render-parameter>
<identifier>myname</identifier>
<qname xmlns:x="http://MyJSR286/">x:name</qname>
</public-render-parameter>
MyJSR286Receiver.war (Receiver Application)
Name of Portlet : MyJSR286Receiver
Context path: myjsrreceiver
MyJSR286ReceiverPortletView.jsp
<%@page session="false" contentType="text/html" pageEncoding="ISO-8859-1" import="java.util.*,javax.portlet.*,com.ibm.myjsr286receiver.*" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<DIV style="margin: 6px">
<H3 style="margin-bottom: 3px">Welcome! ${param.myname}</H3>
</DIV>
portlet.xml
<portlet>
<portlet-name>MyJSR286Receiver</portlet-name>
...
<supported-public-render-parameter>foo</supported-public-render-parameter>
</portlet>
<public-render-parameter>
<identifier>myname</identifier>
<qname xmlns:x="http://MyJSR286/">x:name</qname>
</public-render-parameter>
ScreenShot
Click here to download the sample code.
No comments:
Post a Comment