# How Do I: Establish Interportlet Communication Programatically?

Interportlet communication is best achieved by using event handlers, as described in How Do I: Establish Interportlet Communications with WebLogic Workshop? However, while using listenTo attribute in page flows is no longer a recommended practice for establishing interportlet communications, it is an option. This topic explains how to use multiple page flows that react to browser events such as forms.

To Create Portlets that Share Messages

1. Inside the portal Web application, create a portlets directory.
2. Within this portlets directory, create two new page flows. (A separate directory will be automatically created for each one).
3. Create a portlet for each page flow and place these portlets on a portal.
4. In the Portal, click on the second portlet and set the listenTo attribute to the instanceLabel of the first portlet. (Open the Portal in Design View, click once on the second portlet and find the properties editor.)

   NOTE: The listenTo attribute is associated with the instanceLabel of the other portlet. You can change the definitionLabel without affecting the listenTo behavior.

5. In the .jpf file for the second portlet you can do one of two things.

   The first option is to use the same action method signature as in the first page flow. For example, this action definition is from the page flow controller for portlet 2:

        /**
         * @jpf:action
         * @jpf:forward name="listening" path="listening.jsp"
         */
         public Forward passString1(portlets.j1.j1Controller.Form form)
         {
             thePassedText = form.getText();
             return new Forward( "listening" );
         }

   Or you can add a handler for ActionNotFoundException handler. For example, in the page flow controller for portlet 2, make sure the @jpf:catch annotation is defined at the class level:

       /**
        * @jpf:controller
        * @jpf:catch type="ActionNotFoundException" method="doNothing"
        */

   And in the same page flow controller, that an action method such as the following is defined:

        /**
         * @jpf:exception-handler
         * @jpf:forward name="current" return-to="currentPage"
         */
         protected Forward doNothing( ActionNotFoundException e, String actionName, String message, FormData form )
         {
             return new Forward( "current" );
         }

6. As you edit the page flow, you can verify the navigation by opening a viewer that will preview the pages without the portal.
7. Place the two portlets inside placeholders within your portal.
8. When the navigation and interaction works within the page flow, preview the portlet by navigating to YourWebappp/YourPortalName.portal.

Related Topics

Tutorial: Using Page Flows Inside Portlets

Portal Key Concepts and Architecture

Developing Portal Applications

Handling Exceptions in Page Flows

How Do I: Use Event Handlers to Establish Interportlet Communications?