Interportlet Communication Guide
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Interportlet communications refers to how an event in one portlet controls some aspect of behavior in another portlet. This section describes four interportlet communication samples available from BEA WebLogic Portal's dev2dev site that show you how interportlet commmunications can be implemented. It includes information on the following subjects:
Each sample is comprised of two portlets: a menu portlet and a display portlet, plus a portlet describing the logic behind the selected sample (seeFigure 1-1). The menu portlet appears beneath the selection display portlet to emphasize the point that portlet display order does not affect the behavior of the sample. The description portlet changes when you select a sample from the menu at the bottom of the portlet header (see Figure 1-2).
Figure 1-1 Interportlet Communications Sample Portal
Sample 1 shows interportlet communications between two pageflow portlets. In this example, both the menu portlet (menuController.portlet
) and the menu selection display portlet (selectionReaderController.portlet
) are pageflow portlets.
The selection reader portlet listens to the menu portlet. This is achieved by setting the Listen To
property of the selection reader portlet to the instance label of the menu portlet—in this case, portlet_pfo_menu_instance
.
Warning: the Listen-To mechansim is only suitable for Single-file portals and not streaming portals.
When the selectMenuItem action of the menu's page flow is executed, the same action, if it exists, will subsequently be executed in the selection display page flow. In this simple example the listening page flow sets a pageflow data member that is then bound to the JSP via an invocation of the netui:label
tag.
In this example, the menu portlet (menuController.portlet
) is a pageflow portlet, but the menu selection display portlet (selectionReader.portlet) is not.
The selectMenuItem action in the menu portlet pageflow places the value of the selected menu item in the outer request, accessible by the selection display portlet. Remember, the getRequest()
method in a pageflow returns a request scoped to that pageflow. To share the value of the selected item with the non-pageflow portlet, the selectMenuItem first accesses the outer request using ScopedServletUtils.getOuterRequest(scopedRequest), and then sets an attribute—selectedItem
—on this request. The selection display portlet simply retrieves this attribute from the request in its .jsp
.
In this example, neither the menu portlet (menu.portlet) nor the menu selection display portlet (selectionReader.portlet
) are pageflow portlets.
The menu portlet uses the portal framework's render taglib to create three anchors, each of which, when clicked, will place a menu selection value into the request, and return to the same .jsp
(menu.jsp
) within the portlet. The selection reader .jsp
grabs the menu selection parameter from the request, and displays it, using some scriptlet.
You should be aware that the first three samples are very simple examples of interportlet communication. You can use backing files in these portlets so that "real work" can be accomplished within the init()
, preRender()
, handlePostback()
, and other portal framework lifecycle methods. Note that Sample 4: Non-Pageflow Portlet to Pageflow Portlet, employs a backing file. For more information on backing files, please refer to Understanding Backing Files.
In this example, the menu portlet (menu.portlet
) is not a pageflow portlet, but the menu selection display portlet (selectionReaderController.portle
t) is a pageflow portlet.
The menu portlet exploits a backing file, MenuBacking.java
, to explicitly run a particular action in the selection display pageflow portlet. After this action is run, the backing file of the menu portlet explicitly changes the URI of the selection display portlet—to one.jsp
, two.jsp
, or three.jsp
—based on the result of the executed action. The primary steps in accomplishing this form of inter-portlet communication are:
<selectedItem>
attribute on the scoped request, so that when the ActionResolver runs the pageflow's action, this information will be available to the pageflow. Use the URI in the ActionResult object to set the current content URI for the pageflow portlet.
Refer to the comments in MenuBacking.java for more explicit details. You can find MenuBacking.java and other information on backing files in Understanding Backing Files.
This section descibes how to download and install the interportlet communication code samples.
The samples are available from the BEA WebLogic Portal 8.1 dev2dev site, at:
http://dev2dev.beasys.com/codelibrary/code/interportlet_v1.jsp
Simply click the Interportlet Communication Samples link and follow the dowload process to obtain the file ipc_samples.zip
. This zip file contains the directory interportlets_codes
, which is comprised of the subdirectory portletToPortlet
and the file ipc.portal
.
You can install the samples directly from the download directory or by using BEA WebLogic Workshop.
To install from the download directory:
Using a file extraction tool, such as WinZip, extract both portletToPortlet
and ipc.portal
into a web project, such as sampleportal
(<WebLogic_Home>/samples/portalApp/sampleportal
).
To install from BEA WebLogic Workshop:
Table 1-1 lists the location of each sample within the directory you choose to store it (for example, <WebLogic_Home>/portalApp/sampleportal
)..
Since all four samples appear in the same portal, you only need to open that portal to run them all.
You can open the sample either from within an open browser or by using BEA WebLogic Workshop.
With BEA WebLogic Server running, enter the URL for ipc.portal in the browser address bar; for example, http://localhost:7001/
myWebApp
/ipc.portal
(where myWebApp
is the web application into which you installed ipc.portal
.
To open from BEA WebLogic Workshop:
To run the samples, click the sample you want to see from the menu below the portal header, as shown in Figure 1-2.
Figure 1-2 Interportlet Communication Sample; Portal Header with Menu
That sample appears in the body of the portal; for example, if you selected sample 1, Pageflow on Menu and on Selection Display, the portal would appear as in Figure 1-3
Figure 1-3 Interportlet Communication Sample; Sample 1: Pageflows on Menu and Menu Selection Portlets
To observe interportlet communication with this sample, simply select one of the options in the Menu portlet and view the result in the Menu Selection portlet; for example, if you select Two, the Menu Selection portlet text changes to The selected item is: Two (Figure 1-4).
Figure 1-4 Menu and Menu Selection Portlets; Item Two Selected
Select additional samples and test them, observing the interplay between the Menu and the Menu Selection portlets.
You can easily use these samples in your own applications. You will need to do the following:
![]() ![]() |
![]() |
![]() |