# How Do I: Establish Interportlet Communications with WebLogic Workshop?

The easiest way to implement communication between portlets is by adding event handlers to your portlet by using the Portlet Event Handlers dialog box in WebLogic Workshop. These handlers will listen for events on any portlet in your application and react to those events as required. This tool allows you to visually add event handlers to your portal applications without the need to do any actual coding in your source files. This is the recommended way to implement interportlet communications with WebLogic Portal.

Note: You should avoid having multiple portlets fire incompatible actions when listening on the same event. For example, a poor portal design would be to have two portlets which are both instructed to maximize when a given event happens (or which both cause page change events).

For more information on interportlet communications and WebLogic Portal, please refer to the Interportlet Communications Guide.

To Implement Interportlet Communications by Using WebLogic Workshop:

Note: Before starting this procedure, ensure that WebLogic Workshop is running and you have a portlet displayed in the design view.

1. In the Properties Editor, locate and highlight Event Handlers.

1. Click the ellipsis (...) next to the data field.
   The Portlet Event Handlers dialog box appears.
2. Click Add Handler...
   The Add Handler... context menu appears below the button.
3. Click the type of event you want to handle.

   Event detail fields for the selected event appear in the right portion of the Portlet Event Handlers dialog box and the event type will be listed in the Events: list box and as the detail panel label.

4. If desired, highlight and change the Event Label. This must be a unique identifier within this portlet.
5. If desired, type a brief description of the event in Description.
6. Select when to execute the event handler by checking:
   - Only If Displayed, if you want the event handler to execute only if the portlet to which it is listening is on a page that is displayed, in a window that is not minimized, and is in view mode. (This value is the default so you shouldn't actually have to select it unless you really want to deselect it.
   - From Self Instance Only if your want he event handler to execute only from the current portal. Selecting this value disables all "listen to"-related fields.

   These conditions are optional; if you do not check either or both of them, the event handler will listen to events on all portlets in the application.

7. If you did not select From Self Instance Only, specify the portlet to which this portlet should listen. You have two options:

   - Selecting a non-specific portlet identified by a value of None, This, or Any (where None means not to listen to any portlets, This means to listen to this specific portlet only, and Any means to listen to any portlet in the application.
     To select the portlet this way, open the Listen to: drop-down menu and select None, This, or Any.

   - Selecting a specific portlet from your file system. To select a portlet this way, do one of the following:
     - In Portlet, enter description label for the required portlet and click Add

       The portlet description label appears in the Listen To: list box.

       OR

     - Click the ellipsis button (...) to display an Open file menu. Navigate to the desired .portlet file and double-click it (or select it and click Open).

       The portlet description label appears s in the Listen To: list box.

       In this example, portlet_5_1 is the description label for remoteTest.portlet.

8. Open the Event drop-down menu and select the event that will trigger the handler.

   The event (or events) determine the action that a portlet takes when an event is handled. An event handler can have any number of fire event children.
   Only the Portal Event Handler will display existing events, as shown in the image above. These events are:

   This event... | Fires an action when the portlet...
   onActivation | Becomes visible.
   onDeactivation | Ceases to be visible.
   onMinimize | Is minimized
   onMaximize | Is maximized
   onNormal | Returns to its normal state from either a maximized or minimized state
   onDelete | Is deleted from the portal.
   onHelp | Is in the help mode
   onEdit | Is in the edit mode
   onView | Is in the view mode
   onRefresh | Is refreshed

   For other event handlers, you need to enter a unique event identifier with which the portlets that this portlet intends to communicate can recognize.
9. Click Add Action... to select the action that will occur when the selected event fires.
   The Add Action context menu appears below the button.
   Note: Depending upon the event type you selected, the list of available actions will be different.
10. Select the action you want to fire.
    The Portlet Event Handlers dialog box reformats for selecting an action.
    Depending upon the action you added, the appearance of the Portlet Event Handlers dialog box will differ; for example:
    - If you had selected Change Window Mode, a New Mode label would have appeared in the dialog box and the drop-down list would've shown the modes available with this portlet (see Setting Portlet Modes and States for more information on modes and states)
    - If you ad you selected Activate Page, the right panel would have been blank, as Activate Page has no related properties.

    In this example, the selected action is Change Window State (note that the action name is added to the Events list and is used as the detail label).

11. Open the New State drop-down menu and select the window state you want to use.
    Note: Depending upon the action you selected, this drop-down will have a different label and contents or might require that you enter the action name, in the case of a generic event, custom event, or Page Flow event.
    The selected state appears in the New State data field.
12. Click OK.

> The The Portlet Event Handlers dialog box closes and the event handler just added appears in the Properties Editor.

1. To add more actions to this event, click the Event Handlers ellipsis (..) button to display the Portal Events Handlers dialog box and repeat steps 10 through 13.

Related Topics

Portal Key Concepts and Architecture

How Do I: Establish Interportlet Communication Programatically?

Developing Portal Applications