Skip navigation.

Establishing Interportlet Communications

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

A Simple Example of Establishing IPC

This section describes the process of setting up interportlet communications between two portlets by using the Event handler tool in BEA WebLogic Workshop. This is a simple example in which minimizing one portlet will change the text string in another portlet in the portal.

You should become familiar with the Event Handler tool before attempting to replicate this example. Please refer to How Do I: Establish Interportlet Communications with WebLogic Workshop? in the BEA WebLogic Workshop online help system for more information.

This exercise is comprised of three main steps:

Before You Begin

If you have not set up your development environment as described in Setting Up the Examples, please refer to that section and follow these steps:

After completing these steps, you will have portal domain called ipcDomain and a portal application called ipcTest.

Step 1: Create the Portlets

In this step, you will create two JSP files and the JSP portlets that will surface these files. You will also create a backing file that will contain the instructions necessary to complete the communication between the two portlets (for more information on backing files, please refer to Understanding Backing Files) and add an event handler to one of the portlets. Once you have created the portlets and attached the backing file, you will test the application in your browser.

Note: Before continuing with this procedure, ensure that WebLogic Workshop is running and the ipcTest web application node is expanded.

Create the JSP FIles and Portlets

To create the JSP files the portlets will surface, do the following:

  1. Under the ipcTest node, double-click index.jsp.
  2. index.jsp opens in Design View (Figure 3-1).

    Figure 3-1 index.jsp in Design View

    index.jsp in Design View


     
  3. Click the phrase New Web Application Page to highlight it.
  4. A box will appear around the text and an inner text field will appear in the Property Editor, under General (Figure 3-2).

    Figure 3-2 Properties Menu inner Text Field

    Properties Menu inner Text Field


     
  5. In the inner text field, click the ellipses button (...) to open the inner text dialog box and replace New Web Application Page with the phrase Minimize Me!!! Click OK.
  6. The dialog box closes and Minimize Me!!! appears in the inner text field and in the Design View, as shown in Figure 3-3.

    Figure 3-3 New Text Added to the JSP File

    New Text Added to the JSP File


     
  7. Open the File menu and select Save As...
  8. Save the file as aPortlet.jsp.
  9. Right click aPortlet.jsp in the Application tree and select Generate Portlet... from the context menu.
  10. The Portal Details dialog box appears (Figure 3-4). Note that aPortlet.jsp appears in the Content URI field.

    Figure 3-4 Portal Details Dialog Box for a Portlet

    Portal Details Dialog Box for a Portlet


     
  11. Select Minimizable, Maximizable, and Deletable and click Finish.
  12. aPortlet.portlet will appear under ipcTest in the application tree.

  13. aPortlet.jsp should still be open. If it isn't, reopen it.
  14. Open the File menu and select Save as.
  15. In the Name field of the Save "aPortlet.jsp" as dialog box, enter bPortlet.jsp and click Save.
  16. On the JSP display, click Source View.
  17. The XML code for the JSP file appears.

  18. Copy the code from Listing 3-1 into the JSP, replacing everything from <netui:html> through </netui:html>.

  19.  

Listing 3-1 New JSP Code for bPortlet.jsp

<netui:html>
<% String event = (String)request.getAttribute("minimizeEvent");%>
<head>
<title>
Web Application Page
</title>
</head>
<body>
<p>
Listening for portlet A minimize event:<%=event%>
</p>
</body>
</netui:html>

The source should look like example in Figure 3-5.

Figure 3-5 Updated JSP Source

Updated JSP Source


 
  1. Save the file either by clicking the save button or by opening the File menu and selecting Save.
  2. Repeat steps 6 and 7 to create a JSP portlet for bPortlet.

Create the Backing File

You now need to create the backing file that contains the instructions necessary to complete the communication between two portlets (for more information on backing files, please refer to Understanding Backing Files). To create the backing file, do the following:

  1. Expand the WEB-INF node and right-click src to open a context menu.
  2. Select New>Folder.
  3. The Create New Folder dialog box appears.

  4. In Enter a new folder name, type backing and click OK.
  5. The folder backing will appear under WEB-INF/src.

  6. Right-click backing and select New>Java Class.
  7. The New File dialog box appears.

  8. In Name, enter Listening.java and click Create.
  9. The Source View of the new Java class appears (Figure 3-6).

    Figure 3-6 Listening.java Source File

    Listening.java Source File


     
  10. Copy the code from Listing 3-2 into Listening.java.

  11.  

Listing 3-2 Backing File Code for Listening.java

package backing;
import com.bea.netuix.servlets.controls.content.backing.AbstractJspBacking;
import com.bea.netuix.events.Event;
import com.bea.netuix.events.GenericEvent;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Listening extends AbstractJspBacking 
{ 
    private static boolean minimizeEventHandled = false;

public void handlePortalEvent(HttpServletRequest request,
HttpServletResponse response, Event event)
{
minimizeEventHandled = true;
}
       public boolean preRender(HttpServletRequest request, HttpServletResponse
response)
{
if (minimizeEventHandled){
                     request.setAttribute("minimizeEvent","minimize event handled");
}else{
request.setAttribute("minimizeEvent",null);
}
     // reset
minimizeEventHandled = false;
return true;
}
}
  1. The source should now look like that shown in Figure 3-7.
  2. Figure 3-7 listening.java with Updated Backing File Code

    listening.java with Updated Backing File Code


     
  3. Save Listening.java either by opening the File menu and selecting Save or clicking the Save button.

Attach the Backing File

Now you will attach the backing file created in Create the Backing File to bPortlet. Do the following:

  1. In the Application tree, double-click bPortlet.portlet to open it.
  2. In the Property Editor, under Portlet Properties, type backing.Listening into the Backing File field, as shown in Figure 3-8 and press Tab.
  3. Figure 3-8 Attaching the Backing File in the Property Editor

    Attaching the Backing File in the Property Editor


     
  4. Save the file.

Add the Event Handler to bPortlet

To add the event handler to bPortlet, do the following:

Note: bPortlet.portlet should be displayed in WebLogic Workshop. If it isn't, locate it under ipcTest in the application panel and double-click it.

  1. In the Property Editor, click the ellipses button (...) next to Event Handlers.
  2. The Event Handler dialog box appears (Figure 3-9).

    Figure 3-9 Event Handler Dialog Box

    Event Handler Dialog Box


     
  3. Click Add Handler to open the Event Handler drop-down list.
  4. Select Handle Portal Event.
  5. The Event Handler dialog box expands to allow entry of more details (Figure 3-10).

    Figure 3-10 Event Handler Dialog Box Expanded

    Event Handler Dialog Box Expanded


     
  6. Accept the defaults for all fields except Portlet.
  7. In Portlet, click the ellipses button (...).
  8. The Open dialog box for ipcTest appears.

  9. Double-click aPortlet.portlet.
  10. The Open dialog box closes and Portal_1 appears in the Listen to: list and the Portlet field (Figure 3-11). Portal_1 is the definition label of the portlet to which the event handler will listen.

    Figure 3-11 Adding portlet_1

    Adding portlet_1


     
  11. Click the Event drop-down control to open the list of portal event that the handler can listen for and select onMinimize, as shown in Figure 3-12.
  12. Figure 3-12 Event Drop-down List

    Event Drop-down List


     
  13. Click Add Action... to open the action drop-down list and select Invoke BackingFile Method, as shown in Figure 3-13.
  14. Figure 3-13 Add Action Drop-down List

    Add Action Drop-down List


     

    Invoke BackingFile Method appears on the Events list as a child to Handle Portal Event, as shown in Figure 3-14.

    Figure 3-14 Event List with Action Added

    Event List with Action Added


     
  15. In Method, select pr enter handlePortalEvent (Figure 3-15).
  16. Figure 3-15 Adding the Backing File Method

    Adding the Backing File Method


     
  17. Click OK.
  18. The event handler is added. Note that the Event Handler field in the Property Editor now reads "1 Event Handler."

  19. Save the file.

Step 2: Test the Application

To test the application, do the following:

  1. Create a portal called ipcLocal.portal by doing the following:
    1. Right-click ipcTest and select New>Portal.
    2. In the New File dialog box's File Name field, enter ipcLocal.
    3. Click Create.
    4. When the portal is successfully created, its layout will appear in WebLogic Workshop.

  2. Drag both aPortlet and bPortlet from the Data Palette onto the portal layout, as shown in Figure 3-16.
  3. Figure 3-16 Portal Layout with Portlets Added

    Portal Layout with Portlets Added


     
  4. Save the portal either by clicking the save button or opening the file menu and selecting Save.
  5. Open the Portal Menu and select Open Current Portal...
  6. The portal will render in your browser (Figure 3-17).

    Figure 3-17 ipcLocal Portal in Browser

    ipcLocal Portal in Browser


     
  7. Minimize aPortlet.
  8. Note the content change in bPortlet (Figure 3-18).

    Figure 3-18 ipcLocal Portal with aPortlet Minimized

    ipcLocal Portal with aPortlet Minimized


     

Summary

In this exercise, you added to the portal application components created in Setting Up the Examples two JSP portlets. One portlet, aPortlet, was fairly simple, while the second portlet, bPortlet, surfaced a more complex JSP file, leveraged a backing file, and contained a portal event handler. When you tested the application, you observed how the two portlets communicated when an event occurred on aPortlet. This is called local interportlet communications.

 

Skip navigation bar  Back to Top Previous Next