interportletcommunication@1193634289
TRANSCRIPT
-
7/31/2019 InterPortletCommunication@1193634289
1/27
Implementing JSR 168 inter-portlet
communication using Rational ApplicationDeveloper V6.0 and WebSphere Portal V5.1
Level: Intermediate
Asim Saddal (mailto:[email protected])
Senior IT Specialist, IBM
14 September 2005
Copyright International Business Machines Corporation 2005. All rights reserved.
1 of 27
mailto:[email protected]:[email protected] -
7/31/2019 InterPortletCommunication@1193634289
2/27
Table of contents
Abstract ............................................................................................................................... 3
Introduction ......................................................................................................................... 3
About the sample code .................................................................................................... 3Before you begin ............................................................................................................. 4
Introducing the DemoPortlets scenario ........................................................................... 4Creating DemoPortlet1........................................................................................................ 9
Creating DemoPortlet2...................................................................................................... 10
Enabling the DemoPortlet1 as a source............................................................................. 10Describing the source with WSDL................................................................................ 10
Listing 1. WSDL for the source portlet......................................................................... 13
Enabling DemoPortlet2 as target....................................................................................... 14
Generating the WSDL................................................................................................... 14Listing 2: WSDL for target portlet................................................................................ 18
Modifying the Java Classes............................................................................................... 20Modifying the JSP............................................................................................................. 23Deploy the DemoPortlets.war portlet................................................................................ 24
Conclusion......................................................................................................................... 26
Download .......................................................................................................................... 26Resources .......................................................................................................................... 27
About the author................................................................................................................ 27
2 of 27
-
7/31/2019 InterPortletCommunication@1193634289
3/27
AbstractThis tutorial shows you how to implement JSR 168 compliant cooperative portlets
using IBM Rational Application Developer V6.0 and IBM WebSphere Portal V5.1.
You see how to pass multiple values from the source portlet to the target portlet,without defining a complex data type inside a Web Services Definition (WSDL) file.
IntroductionOne of the most significant advantages of the portlet architecture is the portlets'
ability to communicate with each other to create dynamic, interactive applications.You can use portlet messages to share information, notify each other of a users
actions, or to simply help better manage screen real estate. Messages can be sent toa specific portlet, to all portlets on a page, or to all portlets in a single portlet
application. In order to make full use of this potential, you need to adequatelyarchitect the entire portlet application, anticipating inter-portlet communication.
The term cooperative portlets refers to the capability of portlets on a page to interact
with each other by sharing information. One or more cooperative portlets on a portal
page can automatically react to changes from a source portlet , triggered by anaction or event in the source portlet. Portlets that are targets of the event can react
so that users are not required to make repetitive changes or to take repititiousactions in other portlets on the page.
Cooperation between source and target portlets is facilitated by an IBM
WebSphere Portal runtime entity called theproperty broker. Portlets on a page cancooperate in this way even if they were developed independently, without the
programmer's awareness of the existence of the other cooperative portlets.
The most important difference between portlet messaging and cooperative portlets is
that cooperative portlets are more loosely coupled than portlets using messaging.Cooperative portlets do not have to know the name of the target portlet, even if they
do not broadcast data. The matching of source and target portlets is done at runtimebased on registered properties and actions.
During runtime, the WebSphere Portal property broker is responsible for enabling
cooperative portlets. Therefore, you can rely on the WebSphere Portal propertyboker to enable the passing of complex data between portlets, without needing to
define complex data types inside the WSDL files.
JSR 168 is a specification from the Java Community Process for portlet
development. WebSphere Portal V5.1 provides support for the JSR 168 API. With anIBM extension, WebSphere Portal V5.1 supports cooperative portlets for JSR 168
portlets, in which one JSR 168 portlet can communicate with another JSR 168portlet.
About the sample codeA download accompanies this tutorial. The download includes a WAR file which
contains the two demo portlets with the source code and WSDL files. You can deploy
3 of 27
-
7/31/2019 InterPortletCommunication@1193634289
4/27
the WAR file directly into WebSphere Portal, but you need to create the wires
between them. See Deploy the DemoPortlets.war portlet for more details.
Before you beginTo work through this tutorial, you need to basic knowledge of portlet development
and deployment.
To develop and deploy the sample application, you use the following IBM products:
Rational Application Developer for Rational Software Development Platform V6.0
WebSphere Portal V5.1.x
Introducing the DemoPortlets scenarioIn the DemoPortlets scenario you create two JSR 168 portlets. The DemoPortlet1passes multiple values to the DemoPortlet2 without defining complex data type
inside Web Services Definition (WSDL) file.
DemoPortlet1, as shown in Figure 1, gets three fields of user input and then passes
these values to the target portlet, Demo2Portlet, as shown in Figure 2. DemoPortlet1is the source portlet in this scenario.
4 of 27
-
7/31/2019 InterPortletCommunication@1193634289
5/27
Figure 1. DemoPortlet1 receives user input
5 of 27
-
7/31/2019 InterPortletCommunication@1193634289
6/27
DemoPortlet2 is the target portlet. It receives and then displays the three values
from DemoPortlet1.
Figure 2. DemoPortlet2 displaying values it received from DemoPortlet1
6 of 27
-
7/31/2019 InterPortletCommunication@1193634289
7/27
Creating a JSR 168 portlet project
To develop the application, start the Rational Application Developer (hereafter called
Application Developer).
To create the project:
1. Open the Web perspective by clicking Window => Open Perspective =>Web.
2. Click New => Other.
3. Select Portlet Project (JSR 168) from the list. The New Portlet Project (JSR168) wizard launches, as shown in Figure 4.
Figure 3.
4. Enter DemoPortlets as the Name.
5. Clear the Create a portlet checkbox. You will create your portlets separately inorder to have better control over portlet naming conventions.
7 of 27
-
7/31/2019 InterPortletCommunication@1193634289
8/27
-
7/31/2019 InterPortletCommunication@1193634289
9/27
Creating DemoPortlet1To create the first portlet:
1. In the Project Navigator view, select the DemoPortlets project.
2. Right-click to bring up the context menu, and click New => Portlet. The NewPortlet wizard launches.
3. Enter DemoPortlet1 as the Default Name prefix, and click Next.
Figure 5. New Portlet wizard
4. Accept the default values, and click Finish.
9 of 27
-
7/31/2019 InterPortletCommunication@1193634289
10/27
Creating DemoPortlet2
Create a second portlet in the same project following same steps you used for the
first portlet, but name this one DemoPortlet2.
Enabling the DemoPortlet1 as a source
JSR 168 portlets can cooperate with each other by exchanging properties using the
property broker. A WSDL file describes the publish (or send) attributes to the
property broker.
Describing the source with WSDLTo enable the DemoPortlet1 portlet as a property source:
1. Right-click the portlet in the Project Explorer view.
2. Select Cooperative => Enable Source.
Figure 6. Enabling DemoPortlet1 as source
10 of 27
-
7/31/2019 InterPortletCommunication@1193634289
11/27
In the Enable Cooperative Source wizard, enter these values, as illustrated in Figure
7:
A name for the Data type, such as IDDatatype
The Namespace for the new data type, such as http://demoportlets
What you want your parameter Bound to, such as Request attribute
Figure 7. Specifying first data item as source
The termparameterrefers to how the value will be transferred from the source
portlet to the target portlet. The choices are:
None: This setting implies that you will not specify the way the value is passed, sothe default behavior for portlet
Render parameter: Supports only strings. The string value is bound to the
RenderRequest object. The render parameter can be set during the action phase andretrieved during the render phase of the portlet lifecycle. It cannot be retrieved
during the action phase.
Request parameter: Supports only strings. The string value is bound to the
ActionRequest object, and can be retrieved during the action processing stage of theportlet lifecycle. The parameter value is meaningless at the conclusion of request
processing (that is, it will not persist beyond a single invocation).
Request attribute: Supports any JavaBean type. The bean is bound to theActionRequest object. Lifecycle Request Parameter.
11 of 27
-
7/31/2019 InterPortletCommunication@1193634289
12/27
Session: Supports any JavaBean type. The bean is bound to the session object and
persists for the duration and the portal server.
The Enable Cooperative Source wizard generates a WSDL file that describes the
portlet to the property broker, tagged with a distinctive icon to indicate that it is aproperty source. The WSDL file contains the following sections:
Types: Describes data types (using XML schema) that can be emitted by the source
portlet.Messages: Describes messages that can be produced or consumed by the portlet.
Port Type: Describes the abstract interface of the portlet, as seen by the propertybroker.
Binding: Describes how the abstract interface (port type) is implemented.
To define the second value you want to pass from the first portlet to the target:
1. Right-click the portlet again and select Cooperative->Enable Source2. Define the values indicated in Figure 8.
Figure 8. Specifying second data item as source
12 of 27
-
7/31/2019 InterPortletCommunication@1193634289
13/27
For the third attribute, specify the values shown in Figure 9:
Figure 9. Specifying first data items as source
Listing 1. WSDL for the source portlet
The wizard produces a WSDL file similar to this:
13 of 27
-
7/31/2019 InterPortletCommunication@1193634289
14/27
Define captions and description for and attributes. These fields are optional but are very useful when creating wires.
Enabling DemoPortlet2 as targetJust as you enabled the first portlet to act as a source, you need to enable thesecond portlet to act as a target.
Generating the WSDLYou use the Enable Cooperative Target wizard to generate the WSDL.
To launch the wizard, select the portlet and click Cooperative => Enable Target(this step is nearly identical to enabling cooperative source).
Figure 10. Enabling the second portlet to act as target
14 of 27
-
7/31/2019 InterPortletCommunication@1193634289
15/27
15 of 27
-
7/31/2019 InterPortletCommunication@1193634289
16/27
In the Enable Cooperative Target wizard, enter these values (shown in Figure 11):
Data type: Use the exact same name that you used when you enabled the source
portlet.Namespace: Enter the same one you used for the source.
Action: Use the exact same name that you used when you enabled the source
portlet.Parameter: Use the exact same name that you used when you enabled the sourceportlet.
Bound to: Choose None from the list.
Label and Description: These fields are optional. However, it's a good idea to fillthem because because you can use them if you decide to create wires.
Figure 11. Specifying settings for enabling the target
In order to define the remaining two attributes for the same target portlet, DO NOT
use the wizard. You need to define them inside the WSDL file directly becausewizard only supports simple data types for a single entry. If you try to use the wizard
to define multiple entries, the previous values would be overwritten.
16 of 27
-
7/31/2019 InterPortletCommunication@1193634289
17/27
Open the DemoPortlet2portlet.wsdl file and make the modifications shown in the
WSDL code listing below.
17 of 27
-
7/31/2019 InterPortletCommunication@1193634289
18/27
Listing 2: WSDL for target portlet
18 of 27
-
7/31/2019 InterPortletCommunication@1193634289
19/27
Again, define captions and description for and
attributes.
19 of 27
-
7/31/2019 InterPortletCommunication@1193634289
20/27
Application Developer generates DemoPortlet1portlet.wsdl and
DemoPortlet2portlet.wsdl, as shown in the project view (Figure 12).
Figure 12. Specific settings for enabling the target
Modifying the Java Classes
After defining the attributes and the portlet action in the WSDL file, you need tomodify the Java code for the source and target portlets. In order for a portlet to be a
source of data, you need to use a WSDL file to flag sharable data on the outputpages. In order for a portlet to be a target, you must describe a subset of the portlet
actions, including type information for the action parameters. You use the WSDL file,
with some custom extensions, as the supported format for declaring actions andtheir associated parameters for JSR 168 compliant portlets.
1- Open DemoPortlet1Portlet.java file.
2- Declare the following attributes:
20 of 27
-
7/31/2019 InterPortletCommunication@1193634289
21/27
public static final String FORM_ID = "FormID";
public static final String FORM_NAME = "FormName";
public static final String FORM_STATE = "FormState";
public static final String ACTION_TEXT = "MyAction";
Make sure the values ofFORM_ID, FORM_NAME and FORM_STATE are the samename defined for in the WSDL file.
3- Modify processAction() method
public void processAction(ActionRequest request,
ActionResponse response) throws PortletException,
java.io.IOException {
String id = request.getParameter(FORM_ID);
String name = request.getParameter(FORM_NAME);String state = request.getParameter(FORM_STATE);
request.setAttribute(FORM_ID, id);request.setAttribute(FORM_NAME, name);request.setAttribute(FORM_STATE, state);
}
3- Save the changes.
4- Open DemoPortlet2PortletSessionBean.java and define following attributes:
private String id = "";
private String name = "";
private String state = "";
5- Generate getter and setter methods for the above attributes and save thechanges.
6- Open DemoPortlet2Portlet.java file.
7- Declare the following attributes:
public static final String FORM_ID = "FormID";
public static final String FORM_NAME = "FormName";
public static final String FORM_STATE = "FormState";
public static final String ACTION_TEXT = "MyAction";
Important: Make sure that the values for FORM_ID, FORM_NAME, and
FORM_STATE are the same as the name values defined for in the
WSDL file.
8- Modify processAction() method:
public void processAction(ActionRequest request,
ActionResponse response) throws PortletException,
java.io.IOException {
21 of 27
-
7/31/2019 InterPortletCommunication@1193634289
22/27
DemoPortlet2PortletSessionBean sessionBean =getSessionBean(request);
String id = request.getParameter(FORM_ID);
String name = request.getParameter(FORM_NAME);String state = request.getParameter(FORM_STATE);
sessionBean.setId(id);sessionBean.setName(name);
sessionBean.setState(state);
}
9- Save the changes.
22 of 27
-
7/31/2019 InterPortletCommunication@1193634289
23/27
Modifying the JSPYou need to make the following modifications in the JSP code, so that a user canprovide input values to the source portlet. The target portlet will display the input
values on the page.
1- Open DemoPortlet1PortletView.jsp.
2- Modify the JSP code as follows:
Enter ID:
Enter Name:
Enter State:
3- Save the changes.
4- Open DemoPortlet2PortletView.jsp.
5- Modify the JSP code as follows:
Entered Id is =
Entered Name is =
Entered State is =
6- Save the changes.
23 of 27
-
7/31/2019 InterPortletCommunication@1193634289
24/27
Deploy the DemoPortlets.war portletNow, you export the WAR so that you can deploy the portlet application intoWebSphere Portal 5.0 to test the portlets.
1- Export the DemoPortlets Project as a WAR file.
Figure 13. Exporting the project as a WAR
24 of 27
-
7/31/2019 InterPortletCommunication@1193634289
25/27
2- Install the DemoPortlets.war file in WebSphere Portal Server.
Figure 14. Installing the WAR file (portlet application)
3- After the installation of the portlet is completed, create a page.
4- Place both the portlets on the same page.
5- Create the wires between both portlets by selecting the Wire link on top of thepage.
6- Define a wire for each attribute defined and click Add wire, as shown in thefigure.
25 of 27
-
7/31/2019 InterPortletCommunication@1193634289
26/27
Figure 15. Exporting the project as a WAR
7- After you have created all the wires, click Done.
8- Go to the page where both portlets are placed.
9- Test the portlets by entering dummy data and pressing Submit. You should see
the values on the second portlet.
ConclusionEven though the JSR 168 specification does not include a definition for inter-portletcommunication, WebSphere Portal V5.1 provides an extension for cooperative
portlets which enables one JSR 168 portlet to communicate with another JSR 168portlet. Enterprise portals are filled with opportunities for applying cooperative
portlet capabilities. You can use the simple example you just completed as anexample for applying this capability in your own portal.
DownloadTo get the download file, see the cover page for this tutorial, at:https://www6.software.ibm.com/developerworks/education/websphere/0509_saddal/0509_saddal.html
26 of 27
https://www6.software.ibm.com/developerworks/education/websphere/0509_saddal/0509_saddal.htmlhttps://www6.software.ibm.com/developerworks/education/websphere/0509_saddal/0509_saddal.html -
7/31/2019 InterPortletCommunication@1193634289
27/27
Resources
WebSphere Portal Server V5.1 InfoCenter
http://publib.boulder.ibm.com/pvc/wp/510/ent/en/InfoCenter/index.html
WebSphere Portal product documentationhttp://www.ibm.com/developerworks/websphere/zones/portal/proddoc.html
WSDL specificationshttp://www.w3.org/TR/wsdl
IBM Redbook: IBM Rational Application Developer V6 Portlet Application
Development and Portal Toolshttp://publib-b.boulder.ibm.com/Redbooks.nsf/RedbookAbstracts/sg246681.html
Developing JSF Portlets with Rational Application Developer 6.0 and WebSphere
Portal Server 5.1, Part 1: Developing JSR168 JSF Portletshttp://www.ibm.com/developerworks/rational/library/05/genkin/index.html
Other articles about portlet cooperation:
http://www.ibm.com/developerworks/views/websphere/libraryview.jsp?search_by=coope
rative+portlets&product_by=WebSphere+Portal
Other JSR 168 resources:
http://www.ibm.com/developerworks/views/websphere/libraryview.jsp?search_by=JSR+168&product_by=WebSphere+Portal
WebSphere Portal zonehttp://www.ibm.com/developerworks/websphere/zones/portal/
Rational Application Developer for WebSphere Softwarehttp://www.ibm.com/developerworks/rational/products/rad/
About the authorAsim S Saddal is a Senior IT Specialist with the WebSphere Application
and Portal server practice in the IBM Software Services for WebSphere
(ISSW) in Chicago, Illinois.
http://publib.boulder.ibm.com/pvc/wp/510/ent/en/InfoCenter/index.htmlhttp://www.ibm.com/developerworks/websphere/zones/portal/proddoc.htmlhttp://www.w3.org/TR/wsdlhttp://publib-b.boulder.ibm.com/Redbooks.nsf/RedbookAbstracts/sg246681.htmlhttp://www.ibm.com/developerworks/rational/library/05/genkin/index.htmlhttp://www.ibm.com/developerworks/views/websphere/libraryview.jsp?search_by=cooperative+portlets&product_by=WebSphere+Portalhttp://www.ibm.com/developerworks/views/websphere/libraryview.jsp?search_by=cooperative+portlets&product_by=WebSphere+Portalhttp://www.ibm.com/developerworks/views/websphere/libraryview.jsp?search_by=JSR+168&product_by=WebSphere+Portalhttp://www.ibm.com/developerworks/views/websphere/libraryview.jsp?search_by=JSR+168&product_by=WebSphere+Portalhttp://www.ibm.com/developerworks/websphere/zones/portal/http://www.ibm.com/developerworks/rational/products/rad/http://www.ibm.com/developerworks/rational/products/rad/http://www.ibm.com/developerworks/websphere/zones/portal/http://www.ibm.com/developerworks/views/websphere/libraryview.jsp?search_by=JSR+168&product_by=WebSphere+Portalhttp://www.ibm.com/developerworks/views/websphere/libraryview.jsp?search_by=JSR+168&product_by=WebSphere+Portalhttp://www.ibm.com/developerworks/views/websphere/libraryview.jsp?search_by=cooperative+portlets&product_by=WebSphere+Portalhttp://www.ibm.com/developerworks/views/websphere/libraryview.jsp?search_by=cooperative+portlets&product_by=WebSphere+Portalhttp://www.ibm.com/developerworks/rational/library/05/genkin/index.htmlhttp://publib-b.boulder.ibm.com/Redbooks.nsf/RedbookAbstracts/sg246681.htmlhttp://www.w3.org/TR/wsdlhttp://www.ibm.com/developerworks/websphere/zones/portal/proddoc.htmlhttp://publib.boulder.ibm.com/pvc/wp/510/ent/en/InfoCenter/index.html