Skip navigation.

Interportlet Communication Guide

  Previous Next vertical dots separating previous/next from contents/index/pdf Contents View as PDF   Get Adobe Reader

Using the Interportlet Communication Samples

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:

 


Samples Description

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

Interportlet Communications Sample Portal


 


 

 


Sample 1: Pageflow Portlet to Pageflow Portlet

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.

How It Works

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.

 


Sample 2: Pageflow Portlet to Non-Pageflow Portlet

In this example, the menu portlet (menuController.portlet) is a pageflow portlet, but the menu selection display portlet (selectionReader.portlet) is not.

How It Works

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.

 


Sample 3: Non-Pageflow Portlet to Non-Pageflow Portlet

In this example, neither the menu portlet (menu.portlet) nor the menu selection display portlet (selectionReader.portlet) are pageflow portlets.

How It Works

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.

 


Using Backing Files to Add Functionality

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.

 


Sample 4: Non-Pageflow Portlet to Pageflow Portlet

In this example, the menu portlet (menu.portlet) is not a pageflow portlet, but the menu selection display portlet (selectionReaderController.portlet) is a pageflow portlet.

How It Works

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:

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.

 


Obtaining the Samples

This section descibes how to download and install the interportlet communication code samples.

Dowload the 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.

Install the Samples

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:

  1. Right-click the web project into whichyou want to install the samples and select Import...
  2. Navigate to the download directory and select both portletToPortlet and ipc.portal (under the interportlet_codes directory) and click Import.

 


Location of Samples

Table 1-1 lists the location of each sample within the directory you choose to store it (for example, <WebLogic_Home>/portalApp/sampleportal)..

Table 1-1 Location of Interportlet Communication Samples

Sample

Location

Pageflow Portlet to Pageflow Portlet

portletToPortlet/pageFlowsOnly

Pageflow Portlet to Non-Pageflow Portlet

portletToPortlet/pageFlowMenuOnly

Non-Pageflow Portlet to Non-Pageflow Portlet

portletToPortlet/noPageFlows

Non-Pageflow Portlet to Pageflow Portlet

portletToPortlet/pageFlowSelectionDisplayOnly


 

 


How to Run the Samples

Since all four samples appear in the same portal, you only need to open that portal to run them all.

Open the Portal Application

You can open the sample either from within an open browser or by using BEA WebLogic Workshop.

To open from a browser:

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:

  1. In the Application tree, locate and double-click to open the file ipc.portal.
  2. The portal opens in WebLogic Workshop.

  3. If WebLogic Server is not running, open the Tools menu and select WebLogic Server>Start WebLogic Server.
  4. The server startup routine begins; after a few moments, the server will be started and a green dot will appear at the bottom of the IDE, next to the words "Server Running."

  5. Open the Portal menu and select Open Current Portal.
  6. A browser opens with the interportlet communication sample portal displayed.

Run the Samples

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

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

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

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.

 


Using the Samples in Your Portal

You can easily use these samples in your own applications. You will need to do the following:

  1. Copy the portlet(s) you want to use from the portalApp/sampleportal/portletToPortlet into your project directory.
  2. In each sample you want to use, change the instance and action name of the portlet to match your application needs.
  3. Update the necessary variable in the request parameters to match your application needs.

 

Skip navigation bar  Back to Top Previous Next