Weblogic Portal: Establishing Interportlet Communications
Weblogic Portal: Establishing Interportlet Communications
Weblogic Portal: Establishing Interportlet Communications
Portal ™
Establishing Interportlet
Communications
Overview of Interportlet
Communications
z When maximizing one portlet causes another portlet to change its displayed mode from
View to Edit.
z Selecting an item in a menu portlet will launch a page flow action in a visible content
portlet, causing that portlet’s contents to change.
Service Pack 4 of BEA WebLogic Portal 8.1 introduced a relatively simple tool for implementing
interportlet communications. This tool—a dialog box in WebLogic Workshop—allows you to
easily add event handlers to a portlet and then add actions for those handlers to fire when they
detect the event on another portlet.
This document described how to establish IPC by implementing event handlers. It contains these
subjects:
handlers, Java objects that listen for predefined events on other portlets in the portal and fire
actions when that event occurs.
Event Handlers
Event handlers “listen” for events raised on subscribed portlets and fire an action when a specific
event is detected. Event handlers can listen and react to the following types of events:
z Generic Events
z Portal Events
z Custom Events
z Page Flow Events
z Struts Events
onMinimize Is minimized
onMaximize Is maximized
onNormal Returns to its normal state from either a maximized or minimized state
onRefresh Is refreshed
Custom Events
A custom event is an event that you define; in other words, it is not an event provided
out-of-the-box with WebLogic Portal 8.1. A custom event can pass a developer-defined payload
or fire any other predefined action. Custom events can be fired declaratively or based on a
methods called in a backing file. A user will be able to specify that an event should be handled
by a method in a backing file.
Event Actions
The event handlers fire an action on the listening portlets when that handler detects an event from
another portlet in the application; for example, when the user minimizes the appropriate portlet a
portal event called onMinimize might cause the handler listening for it to fire an action that
invokes a backing file attached to it.
Table 1-2 lists the event actions available.
Change Window Mode Changes the mode from its current mode to a user-specified mode; for
example, from help mode to edit mode.
Change Window State Changes the state from its current state to a user-specified state; for
example, from maximized to delete state.
Fire Custom Event Fires a user-defined custom event. This event needs to be included in the
portlet file.
Invoke BackingFile Runs a method in the backing file attached to the portlet. Backing files allow
Method you to programatically add functionality to a portlet to enable preprocessing
(for example, authentication) prior to rendering the portal controls. For
more information, please refer to Chapter 5, “Understanding Backing
Files”.
2. In the Property Editor for that portlet, click the ellipses button (...) next to Event Handlers
(if no event handlers have been added, the Event handler field will show that. If any event
handlers have been added, the field will indicate the number added).
The tool will appear, as shown in Figure 1-1.
3. Click Add Handler to open the event handler drop-down menu and select a handler.
The dialog box will expand, opening up additional fields you can use to set up the handler
(Figure 1-2).
The entire process of setting up an event handler can all be handled by using this tool. What you
need to do is:
This manual contains two exercises that will step you through the procedures for establishing
interportlet communications. One example uses a portal event handler (Chapter 3, “A Simple
Example of Establishing IPC”), while the other employs both a custom event handler and a page
flow event handler (Chapter 4, “Establishing IPC by Using Custom and Page Flow Events”).
These examples will familiarize you with the workings of the Event Handler tool in the context
of some common uses of that tool.
These examples are specific to interportlet communications within a single portal web
application. They do not apply to federated portal applications. For information on establishing
IPC with federated portals (such as WSRP), please refer to Establishing Interportlet
Communications with Remote Portlets
This section includes information on the following topics:
z Summary
z Next Steps
z Portal Domain: The portal domain is a logically related group of WebLogic Server
resources that contain the application server, including the administration server and
managed servers, used by the portal, represented by a config.xml file.
z Portal Application: This component, also called the “enterprise” application, consists of
one or more portal web application (or “project”) modules, EJB modules, and resource
adapters. It might also include a client application. An enterprise application is defined by
an application.xml file, which is the standard J2EE deployment descriptor for
enterprise applications. You can have more that one portal application per domain.
z Portal Web Application: Alternately referred to as the “portal project,” this component is
the specific portal. It contains the elements of the portal framework necessary to build and
render the portal, such as the WebLogic Portal JSP tags, APIs and the default framework
files. The
In this section, you will create the domain and enterprise application that you will use in the
exercises included in Chapter 3, “A Simple Example of Establishing IPC” and Chapter 4,
“Establishing IPC by Using Custom and Page Flow Events”. In this exercise, the root directory
for your domain should be BEA_HOME\user_projects\domains; for the applications and all of
their components, it’s BEA_HOME\user_projects\applications (where BEA_HOME is the
directory where you installed BEA WebLogic Platform). These are default directories that BEA
WebLogic Platform creates upon installation.
3. Follow the prompts using the value specified in Table 2-1. Click Next when you are
finished with each dialog box.
3. Click Create.
When the application is successfully created, it will appear in the application panel, as
shown in Figure 2-1.
1. In the file tree, right-click the application name (ipcTest) and select New>Project, as shown
in Figure 2-2.
2. In the left pane of the dialog box, select Portal and, in Filename, enter ipcTest. Click
Create.
The project is updated (you will see a progress meter). Once the update is complete, the
project appears as a directory in the file tree (Figure ).
Summary
Upon completion of the preceding procedures, you will have created a domain, an enterprise
application, and a portal web application. The file tree in the left-hand pane of WebLogic
Workshop should look like the example in Figure 2-1. These will be the domain and enterprise
application you will use for the exercises in this document.
Next Steps
With a development environment completed, you next will complete the exercises described in
their respective chapters:
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:
3. 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.
The dialog box closes and Minimize Me!!! appears in the inner text field and in the Design
View, as shown in Figure 3-3.
6. Right click aPortlet.jsp in the Application tree and select Generate Portlet... from the
context menu.
The Portal Details dialog box appears (Figure 3-4). Note that aPortlet.jsp appears in the
Content URI field.
10. In the Name field of the Save “aPortlet.jsp” as dialog box, enter bPortlet.jsp and click
Save.
12. Copy the code from Listing 3-1 into the JSP, replacing everything from <netui:html>
through </netui:html>.
<netui:html>
<% String event = (String)request.getAttribute("minimizeEvent");%>
<head>
<title>
13. Save the file either by clicking the save button or by opening the File menu and selecting
Save.
1. Expand the WEB-INF node and right-click src to open a context menu.
2. Select New>Folder.
The Create New Folder dialog box appears.
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;
minimizeEventHandled = true;
}
// reset
minimizeEventHandled = false;
return true;
}
7. The source should now look like that shown in Figure 3-7.
8. Save Listening.java either by opening the File menu and selecting Save or clicking the
Save button.
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.
1. In the Property Editor, click the ellipses button (...) next to Event Handlers.
The Event Handler dialog box appears (Figure 3-9).
6. Double-click aPortlet.portlet.
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.
7. 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.
8. Click Add Action... to open the action drop-down list and select Invoke BackingFile
Method, as shown in Figure 3-13.
Invoke BackingFile Method appears on the Events list as a child to Handle Portal Event, as
shown in Figure 3-14.
b. In the New File dialog box’s File Name field, enter ipcLocal.
c. Click Create.
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. Save the portal either by clicking the save button or opening the file menu and selecting
Save.
5. Minimize aPortlet.
Note the content change in bPortlet (Figure 3-18).
Summary
In this exercise, you added to the portal application components created in Chapter 2, “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.
z A Find Customer lookup portlet into which users will enter the name of a customer.
z A Find Customer Information portlet, which displays information about the customer
whose name was submitted in the customer lookup portlet
z An Find Orders portlet, which displays order information for the customer whose name
was submitted in the customer lookup portlet.
When initially rendered, the completed portal will look like the example in Figure 4-1.
Once the customer name is submitted from Customer Lookup portlet, the portal will look like the
example in Figure 4-2
invokes the attached backing file and executes the specified method. Backing files can have
multiple methods, any of which are made available to the event handler.
Backing files are Java classes that implement the
com.bea.netuix.servlets.controls.content.backing.JspBacking interface or extend
the com.bea.netuix.servlets.controls.content.backing.AbstractJspBacking
interface abstract class. They allow you to you to programatically add functionality to a portlet,
enabling preprocessing (for example, authentication) prior to rendering the portal controls.
Before attempting this exercise, we recommend that you refer to Chapter 5, “Understanding
Backing Files.”
1. Right-click the project name (ipcTest) and select New>Folder (Figure 4-3).
3. Repeat steps 1 and 2 to create two more folders. Name these folders:
– Orders_LookUp (note the use of capitalization in “LookUp”; you must type this word
exactly as shown here)
– portlets
When you are done creating the folders, the project root should look like the example in
Figure 4-6.
4. Next, create the backing folder. This folder will store the backing files you will create in a
few moments. To do so, open the ipcTest/WEB-INF/src folder and repeat steps 1 and 2
(Figure 4-7):
5. In the New Folder dialog box, enter backing and click OK.
The backing file will appear under WEB-INF/src in the file tree (Figure 4-8):
Summary
With the completion of step 2, you have added all the new folders required by the application.
Note that when you create the page flows in later steps, an additional folder for each page flow
will be created under the folder that contains the page flow.
Figure 4-10 New File Dialog Box; Common and Java Class Selected
c. Delete all content in the file editor and replace it with the entire code in Listing 4-1.
package backing;
import com.bea.netuix.servlets.controls.content.backing.JspBacking;
import com.bea.netuix.servlets.controls.content.backing.AbstractJspBacking;
import com.bea.netuix.events.Event;
import com.bea.netuix.events.GenericEvent;
import com.bea.netuix.events.PageFlowEvent;
import com.bea.netuix.servlets.controls.portlet.backing.PortletBackingContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FindCustomerBacking extends AbstractJspBacking
{
public void foundCustomer(HttpServletRequest request, HttpServletResponse
response, Event event)
{
// Get result from form post and inject inside remote IPC
PortletBackingContext context =
PortletBackingContext.getPortletBackingContext(request);
String message = request.getParameter(context.getInstanceLabel() +
"{actionForm.name}");
context.fireCustomEvent("myCustomEvent", message);
}
}
d. Save the file by either clicking the Save icon or by opening the File menu and selecting
Save.
b. Click Create.
The file is created (it will appear under WEB-INF/src/backing in the file tree) and a
backing file template appears in the file editor.
c. Delete all existing code in the file editor and replace it with the entire code in Listing 4-2.
package backing;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.bea.netuix.events.Event;
import com.bea.netuix.events.CustomEvent;
import com.bea.netuix.servlets.controls.content.backing.AbstractJspBacking;
{
public void listenCustomerName( HttpServletRequest request,
HttpServletResponse response, Event event)
{
mySession.setAttribute("customerName", message);
d. Save the file by either clicking the Save icon or by opening the File menu and selection
Save.
a. Repeat steps a through c in step 1, above; however, in File name (step b) enter
ReceiveCustomerInfo.
b. Click Create.
The file is created and a backing file template appears in the file editor
c. Delete all existing code in the file editor and replace it with the entire code in Listing 4-2.
package backing;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.bea.netuix.events.Event;
import com.bea.netuix.events.CustomEvent;
import com.bea.netuix.servlets.controls.content.backing.AbstractJspBacking;
mySession.setAttribute("customerName", message);
d. Save the file by either clicking the Save icon or by opening the File menu and selection
Save.
Summary
With the completion of Step 3, you have created the necessary backing files and have stored them
in the WEB-INF/src/backing folder. That folder should look like the example in Figure 4-13.
Backing Files
Added
Note: To save you time and to reduce the chance of entry errors when creating these files, we
have provided the necessary code in this document. If you are reading this online
(HTML), you can simply cut and paste the code into the appropriate empty file. If you
are using a hardcopy or PDF version of this document and cannot obtain an online copy,
you can type the code exactly as it appears in the code samples.
1. On the file tree, right-click Customer_Lookup and select New > Page Flow (Figure 4-14).
2. In Page Flow Name, enter findCustomer; note that the same text replaces the string
Newpageflow1 in the Controller Name field, so that this field reads
“FindCustomerController” (the lowercase “f” in Page Flow Name is translated to a capital
“F” in Controller Name).
3. Click Next.
The Select Page Flow Type dialog box appears (Figure 4-16).
and FindCustomerController.jpf (Figure 4-18) appears in the file tree. Note that when
you create this page flow, a new folder bearing the page flow name (findCustomer) appears
in the Customer_Lookup folder (Figure 4-18) and an additional JSP, index.jsp is
created. The findCustomer folder will host the files that comprise this portlet and
index.jsp will serve as a template for the result.jsp file.
6. Highlight the entire contents of the Designer and delete it, so that the Source View is empty.
7. Copy the code sample in Listing 4-4 and paste it into the empty Page Flow Designer Source
View.
package Customer_Lookup.findCustomer;
import com.bea.wlw.netui.pageflow.FormData;
import com.bea.wlw.netui.pageflow.Forward;
import com.bea.wlw.netui.pageflow.PageFlowController;
/**
* @jpf:controller
* @jpf:view-properties view-properties::
* <!-- This data is auto-generated. Hand-editing this section is not
* recommended. -->
* <view-properties>
* <pageflow-object id="pageflow:/Customer_Lookup/findCustomer/
* FindCustomerController.jpf"/>
* <pageflow-object id="action:begin.do">
* <property value="80" name="x"/>
* <property value="100" name="y"/>
* </pageflow-object>
* <pageflow-object id="action:findCustomerInfo.do#Customer_Lookup.
* findCustomer.FindCustomerController.FindCustomerInfoForm">
* <property value="680" name="x"/>
* <property value="100" name="y"/>
* </pageflow-object>
* <pageflow-object id="action-call:@page:findCustomer.jsp@#@action:
* findCustomerInfo.do#Customer_Lookup.findCustomer.FindCustomerController.
* FindCustomerInfoForm@">
* <property value="276,460,460,644" name="elbowsX"/>
* <property value="92,92,92,92" name="elbowsY"/>
* <property value="East_1" name="fromPort"/>
* <property value="West_1" name="toPort"/>
* </pageflow-object>
* <pageflow-object id="page:findCustomer.jsp">
* <property value="240" name="x"/>
* <property value="100" name="y"/>
* </pageflow-object>
* <pageflow-object id="page:result.jsp">
* <property value="560" name="x"/>
* <property value="100" name="y"/>
* </pageflow-object>
* <pageflow-object id="forward:path#success#findCustomer.
* jsp#@action:begin.do@">
* <property value="116,160,160,204" name="elbowsX"/>
* <property value="92,92,92,92" name="elbowsY"/>
* <property value="East_1" name="fromPort"/>
* <property value="West_1" name="toPort"/>
* <property value="success" name="label"/>
* </pageflow-object>
* <pageflow-object
* id="forward:path#success#result.jsp#@action:
* findCustomerInfo.do#Customer_Lookup.findCustomer.FindCustomerController.
* FindCustomerInfoForm@">
* <property value="644,620,620,596" name="elbowsX"/>
* <property value="81,81,81,81" name="elbowsY"/>
* <property value="West_0" name="fromPort"/>
* <property value="East_0" name="toPort"/>
* <property value="success" name="label"/>
* </pageflow-object>
* <pageflow-object id="formbeanprop:Customer_Lookup.findCustomer.
* FindCustomerController.FindCustomerInfoForm#name#java.lang.String"/>
* <pageflow-object id="formbean:Customer_Lookup.findCustomer.
* FindCustomerController.FindCustomerInfoForm"/>
* <pageflow-object id="action-call:@page:result.jsp@#@action:
* findCustomerInfo.do#Customer_Lookup.findCustomer.FindCustomerController.
* FindCustomerInfoForm@">
* <property value="596,620,620,644" name="elbowsX"/>
* <property value="92,92,81,81" name="elbowsY"/>
* <property value="East_1" name="fromPort"/>
* <property value="West_0" name="toPort"/>
* </pageflow-object>
* </view-properties>
* ::
*/
// For an example of page flow exception handling see the example "catch"
and "exception-handler"
// annotations in {project}/WEB-INF/src/global/Global.app
/**
* This method represents the point of entry into the pageflow
* @jpf:action
* @jpf:forward name="success" path="findCustomer.jsp"
*/
/**
* @jpf:action
* @jpf:forward name="success" path="result.jsp"
*/
/**
* FormData get and set methods may be overwritten by the Form Bean editor.
*/
Note: You might see two “File could not be found” warnings (indicated by a green squiggle) in
the Page Flow Designer. You can ignore them, as they refer to files that you will create
in the next two steps.
8. Save the file either by clicking the Save icon or by opening the File menu and selecting
Save.
Create findCustomer.jsp
To create findCustomer.jsp, use this procedure:
1. Right-click findCustomer in the file tree and select New > JSP file (Figure 4-20).
2. Ensure that Web User Interface and JSP File are selected; if not, do so now.
The file is created; a new JSP template will appear in the JSP Designer (Figure 4-22):
and the new file appears in the findCustomer folder (Figure 4-23).
4. At the bottom of the JSP Designer, click Source View to display the JSP code.
<netui:html>
<body>
<p> Find Support Information </p>
<netui:form action="findCustomerInfo">
<div>
Name:
7. Save the file either by clicking the Save icon or by opening the File menu and selecting
Save.
Create result.jsp
result.jsp contains the presentation logic for the final page of the successful execution of the
findCustomer page flow (findCustomerController.jpf). This page renders after the name
submitted in the Customer Lookup portlet is authenticated and will present specified customer
data.
To create result.jsp, use this procedure.
2. Select Rename to open the file rename function and replace index.jsp with result.jsp
(Figure 4-25).
3. In the JSP Designer, select Source View to display the JSP code.
5. Copy the code listing in Listing 4-6 and paste it into the JSP designer.
<body>
<p>
Support Case Information
</p>
Customer Name:
<%=session.getAttribute("customerName")
%>
<%
session.setAttribute("customerName", "");
%>
<netui:form action="findCustomerInfo">
<netui:label value="{actionForm.name}"/>
</netui:form>
<div>
<br>
</div>
</body>
</netui:html>
6. Save the file either by clicking the Save icon or by opening the File menu and selecting
Save.
Note: If you reopen FindCustomerController.jpf after saving both JSPs, you will see that
the warnings described in the note following Listing 4-4 do not appear.
Note that Title and Content URL are already filled in (Figure 4-28) based upon the page
flow name.
4. Click Finish.
The new portlet appears in the Customer_Lookup/findCustomer folder (Figure 4-29).
2. In the Portlet Window section of the Property Editor, select Backing File.
The field opens to accept text entry (Figure 4-31).
1. With the portlet open in the Portlet Designer (Figure 4-30), locate in the Portlet Window
section of the Property Editor the property Event Handlers.
2. Mouse over the Event Handlers data entry field (it will read “No event handlers”) to open
the field for edit (Figure 4-32).
Figure 4-35 Event Handler Tool with Handle Custom Event Selected
6. Fill out the Handle Custom Event fields as described in Table 4-1.
Event Label handleCustomEvent1 (this default value should appear when you select
Handle Custom Event from the Add Handler list)
Event: myCustomEvent
Figure 4-37 Event Handler with Invoke BackingFile Method Added as Action
9. Click the Method drop-down control to display a list of available methods (Figure 4-38).
12. Click Add Action to open the Action drop-down menu and select Invoke PageFlow
Method.
The dialog box refreshes and the Action edit box appears in the right-hand pane.
14. Click OK to close the dialog box and press [Tab] to close the Event Handlers data field.
15. Click the Save Files icon or open the File menu and select Save All.
exactly as you create the Find Customer page flow, described in Create the Page Flow
(FindCustomerController.jpf), although obviously with different data included.
To create the FindOrderController.jpf, use this procedure:
3. Click Next
The Page Flow Wizard - Select Page Flow Type dialog box appears.
– A schematic representation of the default page flow appears in the Page Flow Designer
(Figure 4-40).
Figure 4-40 Default Page Flow Schematic in Page Flow Designer — Flow View
package Orders_LookUp.findOrder;
import com.bea.wlw.netui.pageflow.FormData;
import com.bea.wlw.netui.pageflow.Forward;
import com.bea.wlw.netui.pageflow.PageFlowController;
/**
* @jpf:controller
* @jpf:view-properties view-properties::
* <!-- This data is auto-generated. Hand-editing this section is not
* recommended. -->
* <view-properties>
* <pageflow-object id="pageflow:/Orders_LookUp/findOrder/
* FindOrderController.jpf"/>
* <pageflow-object id="action:begin.do">
* <property value="80" name="x"/>
* <property value="100" name="y"/>
* </pageflow-object>
* <pageflow-object id="action:findOrders.do#Orders_LookUp.findOrder.
* FindOrderController.FindOrdersForm">
* <property value="420" name="x"/>
* <property value="100" name="y"/>
* </pageflow-object>
* <pageflow-object id="action-call:@page:findOrderForm.jsp@#@action:
* findOrders.do#Orders_LookUp.findOrder.FindOrderController.
* FindOrdersForm@">
* <property value="276,330,330,384" name="elbowsX"/>
* <property value="92,92,92,92" name="elbowsY"/>
* <property value="East_1" name="fromPort"/>
* <property value="West_1" name="toPort"/>
* </pageflow-object>
* <pageflow-object id="page:findOrderForm.jsp">
* <property value="240" name="x"/>
* <property value="100" name="y"/>
* </pageflow-object>
* <pageflow-object id="page:orderResults.jsp">
* <property value="600" name="x"/>
* <property value="100" name="y"/>
* </pageflow-object>
* <pageflow-object id="forward:path#success#findOrderForm.jsp#@action:
* begin.do@">
* <property value="116,160,160,204" name="elbowsX"/>
* <property value="92,92,92,92" name="elbowsY"/>
* <property value="East_1" name="fromPort"/>
* <property value="West_1" name="toPort"/>
* <property value="success" name="label"/>
* </pageflow-object>
* <pageflow-object id="forward:path#success#orderResults.jsp#@action:
* findOrders.do#Orders_LookUp.findOrder.FindOrderController.
* FindOrdersForm@">
* <property value="456,510,510,564" name="elbowsX"/>
* <property value="92,92,92,92" name="elbowsY"/>
* <property value="East_1" name="fromPort"/>
* <property value="West_1" name="toPort"/>
* <property value="success" name="label"/>
* </pageflow-object>
* <pageflow-object id="formbeanprop:Orders_LookUp.findOrder.
* FindOrderController.FindOrdersForm#customer_name#java.lang.String"/>
* <pageflow-object id="formbeanprop:Orders_LookUp.findOrder.
* FindOrderController.FindOrdersForm#order_id#java.lang.String"/>
* <pageflow-object id="formbean:Orders_LookUp.findOrder.FindOrderController.
* FindOrdersForm"/>
* <pageflow-object id="action-call:@page:orderResults.jsp@#@action:findOrders.
* do#Orders_LookUp.findOrder.FindOrderController.FindOrdersForm@">
* <property value="564,510,510,456" name="elbowsX"/>
* <property value="92,92,81,81" name="elbowsY"/>
/**
* This method represents the point of entry into the pageflow
* @jpf:action
* @jpf:forward name="success" path="findOrderForm.jsp"
*/
protected Forward begin()
{
return new Forward("success");
}
/**
* @jpf:action
* @jpf:forward name="success" path="orderResults.jsp"
*/
protected Forward findOrders(FindOrdersForm form)
{
return new Forward("success");
}
/**
* FormData get and set methods may be overwritten by the Form Bean editor.
*/
public static class FindOrdersForm extends FormData
{
private String order_id;
this.customer_name = customer_name;
}
5. Save the file either by clicking the Save icon or opening the File menu and selecting Save.
Note: You might see two “File could not be found” warnings (indicated by a green squiggle) in
the Page Flow Designer. You can ignore them, as they refer to files that you will create
in the next two steps.
FindOrderController.jpf is created.
Create findOrderForm.jsp
Next, you need to create one of the two JSPs required for the page flow to run successfully.
findOrder.jsp provides the presentation logic for the initial portlet view. From this portlet, you
can launch the page flow by submitting a customer name. In this example, the page flow is
launched when the Order LookUp portlet hears a name submitted on the Customer Lookup
portlet.
To create findOrderForm.jsp, use this procedure.
– The text “New Web Application Page” appears in the JSP Designer (Figure 4-42). This
is the default JSP.
<netui:html>
<head>
<title>
Find Order
</title>
</head>
<body>
<p> Find Order </p>
<%= //session.getAttribute("customerName")
%>
<netui:form action="findOrders">
<table>
<tr valign="top">
<td>Customer_name:</td>
<td>
<netui:textBox dataSource="{actionForm.customer_name}"/>
</td>
</tr>
<tr valign="top">
<td>Order_id:</td>
<td>
<netui:textBox dataSource="{actionForm.order_id}"/>
</td>
</tr>
</table>
<br/>
<netui:button value="Find Orders" type="submit"/>
</netui:form>
</body>
</netui:html>
6. Save the file either by clicking the Save icon or opening the File menu and selecting Save.
findOrderForm.jsp is created.
Create orderResults.jsp
The second JSP you need to create is orderResults.jsp. This file provides the presentation
logic for displaying the results of the order lookup for the customer specified in the Customer
Name or Order ID fields; however, in this example, it will return order information for the
customer name submitted in the Customer Lookup portlet.
To create orderResults.jsp, use this procedure.
4. Copy the code sample in Listing 4-9 and paste it into the JSP Designer.
<netui:label value="{actionForm.customer_name}"/>
</netui:form>
<br>
Order 001<br>
Order 002<br>
Order 003<br>
Order 004<br>
<br>
</body>
</netui:html>
5. Save the file either by clicking the Save or opening the File menu and selecting Save.
6. Right-click index.jsp in the file tree to open a context menu and select Rename.
The node is opened for renaming.
The Portlet Wizard - Portlet Details dialog box appears. Note that the Title and Portlet URI
fields are already completed.
3. Click Finish.
The portlet is created and appears in the file tree under Orders_LookUp/findOrder.
2. In the Portlet Window section of the Property Editor, select Backing File.
The field opens to accept text entry.
Note: Do not include the filetype (.java). WebLogic Workshop interprets the dot-separators
in this field as filepath separators and, if .java is included, will look for a file called
java in a non-existent folder called backing/FindCustomerBacking.
4. Save the file by either clicking the Save icon or by opening the File Menu and selecting
Save.
The backing file is attached.
1. With the portlet open in the Portlet Designer (Figure 4-30), locate in the Portlet Window
section of the Property Editor the property Event Handlers.
2. Mouse over the Event Handlers’ data entry field (it will read “No event handlers”) to open
the field for edit.
Figure 4-47 Event Handler Tool with Handle Custom Event Selected
6. Fill out the Handle Custom Event fields as described in Table 4-2.
Event Label handleCustomEvent1 (this default value should appear when you select
Handle Custom Event from the Add Handler list)
Event: myCustomEvent
Figure 4-49 Event Handler with Invoke BackingFile Method Added as Action
12. Click the Method drop-down control to display a list of available methods.
15. Click the Save Files icon or open the File menu and select Save All.
Summary
At this point, you have completed the Order Lookup Portlet for the ipcText Web application. To
verify that you’ve created all files necessary, compare the Orders_LookUp folder in your file tree
with that in Figure 4-51. Your file tree should match the tree in the example.
3. Click Next
The Page Flow Wizard - Select Page Flow Type dialog box appears.
6. Highlight the entire contents of the Page Flow Designer and delete it, so that the Source
View is empty.
7. Copy the code sample in Listing 4-10 and paste it into the empty Page Flow Designer
Source View.
package portlets.findCustomer;
import com.bea.wlw.netui.pageflow.FormData;
import com.bea.wlw.netui.pageflow.Forward;
import com.bea.wlw.netui.pageflow.PageFlowController;
/**
* @jpf:controller
* @jpf:view-properties view-properties::
* <!-- This data is auto-generated. Hand-editing this section is not
* recommended. -->
* <view-properties>
* <pageflow-object id="pageflow:/portlets/findCustomer/
* FindCustomerController.jpf"/>
* <pageflow-object id="action:begin.do">
* <property value="80" name="x"/>
* <property value="100" name="y"/>
* </pageflow-object>
* <pageflow-object id="page:index.jsp">
* <property value="240" name="x"/>
* <property value="100" name="y"/>
* </pageflow-object>
* <pageflow-object id="forward:path#success#index.jsp#@action:begin.do@">
* <property value="116,160,160,204" name="elbowsX"/>
* <property value="92,92,92,92" name="elbowsY"/>
* <property value="East_1" name="fromPort"/>
* <property value="West_1" name="toPort"/>
* <property value="success" name="label"/>
* </pageflow-object>
* <pageflow-object id="page:result.jsp">
* <property value="580" name="x"/>
* <property value="100" name="y"/>
* </pageflow-object>
* <pageflow-object id="action:findCustomer.do#portlets.findCustomer.
* FindCustomerController.FindCustomerForm">
* <property value="420" name="x"/>
* <property value="100" name="y"/>
* </pageflow-object>
* <pageflow-object id="forward:path#success#result.jsp#@action:findCustomer.
* do#portlets.findCustomer.FindCustomerController.FindCustomerForm@">
* <property value="456,500,500,544" name="elbowsX"/>
* <property value="92,92,92,92" name="elbowsY"/>
* <property value="East_1" name="fromPort"/>
* <property value="West_1" name="toPort"/>
* <property value="success" name="label"/>
* </pageflow-object>
* <pageflow-object id="formbean:portlets.findCustomer.FindCustomerController.
* FindCustomerForm"/>
* <pageflow-object id="formbeanprop:portlets.findCustomer.
* FindCustomerController.FindCustomerForm#name#java.lang.String"/>
* <pageflow-object id="formbeanprop:portlets.findCustomer.
* FindCustomerController.FindCustomerForm#company#java.lang.String"/>
* <pageflow-object id="action-call:@page:index.jsp@#@action:findCustomer.
* do#portlets.findCustomer.FindCustomerController.FindCustomerForm@">
* <property value="276,330,330,384" name="elbowsX"/>
* <property value="92,92,92,92" name="elbowsY"/>
* <property value="East_1" name="fromPort"/>
* <property value="West_1" name="toPort"/>
* </pageflow-object>
* </view-properties>
* ::
*/
public class FindCustomerController extends PageFlowController
{
/**
* This method represents the point of entry into the pageflow
* @jpf:action
* @jpf:forward name="success" path="index.jsp"
*/
protected Forward begin()
{
/**
* @jpf:action
* @jpf:forward name="success" path="result.jsp"
*/
protected Forward findCustomer(FindCustomerForm form)
{
return new Forward("success");
}
/**
* FormData get and set methods may be overwritten by the Form Bean editor.
*/
public static class FindCustomerForm extends FormData
{
private String company;
Note: You might see a “File could not be found” warning (indicated by a green squiggle) in the
Page Flow Designer. You can ignore this warning, as it refers to a file, result.jsp, that
you will create in Create result.jsp.
8. Save the file either by clicking the Save icon or by opening the File menu and selecting
Save.
Update index.jsp
Since this is the “launching pad” for the three page flows in the Web application (that is, when a
name is submitted in this portlet, through interportlet communications, page flow actions will
occur on the portlets created in Step 3: Create the Customer Lookup Results Portlet and Step 4:
Create the Orders Lookup Portlet, as well as this one), this exercise will conform to the best
practice of beginning this page flow with index.jsp file.
This JSP provides the presentation logic for the Customer Lookup portlet before a customer name
is submitted. Once a name is submitted, that logic will be superseded by the presentation logic in
result.jsp, which we will create in the next step. When you created the page flow in Create
the Page Flow (FindCustomerController.jpf), the template for index.jsp was also created and
placed in portlets/findCustomer.
To create index.jsp, use this procedure.
3. In the JSP Designer, select the entire code listing and delete it.
Copy the code sample in Listing 4-11 and paste it into the JSP Designer.
<netui:form action="findCustomer">
<table>
<tr valign="top">
<td>Company:</td>
<td>
<netui:textBox dataSource="{actionForm.company}"/>
</td>
</tr>
<tr valign="top">
<td>Name:</td>
<td>
<netui:textBox dataSource="{actionForm.name}"/>
</td>
</tr>
</table>
<br/>
<netui:button value="findCustomer" type="submit"/>
</netui:form>
</body>
</netui:html>
4. Save the file by either clicking the Save icon or opening the File menu and selecting Save.
Create result.jsp
Next, create the result.jsp file. This file contains the presentation logic that will format the
display of information returned to this portlet upon successful rendering of the
FindCustomerController page flow. This logic will supersede that contained in index.jsp.
To create result.jsp, use this procedure.
The JSP Designer refreshes, revealing the code for the default JSP.
4. Select the entire default JSP code listing and delete it.
5. Copy the code sample in Listing 4-12 and paste it into the JSP Designer.
<netui:form action="findCustomer">
6. Save the file by either clicking the Save icon or by opening the File menu and selecting
Save.
Note: If you reopen FindCustomerController.jpf after saving result.jsp, you will see
that the warning described in the note following Listing 4-10 is gone.
4. Click Finish.
The new portlet appears in the portlets/findCustomer folder.
2. In the Portlet Window section of the Property Editor, select Backing File.
The field opens to accept text entry.
Note: Do not include the filetype (.java). WebLogic Workshop interprets the dot-separators
in this field as filepath separators and, if .java is included, will look for a file called
java in a non-existent folder called backing/FindCustomerBacking folder.
1. With the portlet open in the Portlet Designer, locate in the Portlet Window section of the
Property Editor the property Event Handlers.
2. Mouse over the Event Handlers’ data entry field (it will read “No event handlers”) to open
the field for edit.
Figure 4-55 Event Handler Tool with Handle PageFlow Event Selected
6. Fill out the Handle Custom Event fields as described in Table 4-3.
Event Label handlePageFlowEvent1 (this default value should appear when you select
Handle Custom Event from the Add Handler list)
Action: findCustomer
Figure 4-57 Event Handler with Invoke BackingFile Method Added as Action
12. Click the Save Files icon or open the File menu and select Save All.
Summary
With the event handlers created for the Customer Lookup portlet, you have finished creating all
three portlets for this exercise. To verify that you have created all of the necessary files, please
compare the file tree in your current version of WebLogic Workshop to the example in Figure .
The next step is to add the three portlets you just created to a portal, as described in Step 6: Create
and Populate the Portal File.
1. In the file tree, right-click the Web application name (ipcTest) and select New>Portal
(Figure 4-60).
Figure 4-61 New File Dialog Box Configured for Creating a New Portal
– The three portlets created for this exercise appear in the Data Palette (Figure 4-63).
– The file AW.portal appears in the file tree at the same level as the individual portlet
folders (Figure 4-64).
4. Save the file by either clicking the Save icon or by opening the file menu and selecting
Save.
1. Select each portlet in the Data Palette and drag it to the appropriate position in the portal, as
illustrated in Figure 4-65.
2. Save the portal either by clicking the Save icon or by opening the File menu and selecting
Save.
1. Start the server by opening the Tools menu and selecting WebLogic Server>Start WebLogic
Server.
A progress meter (Figure 4-66), indicating that the server is starting, appears.
The server takes a few moments to start. When the progress meter closes, the server is
running. Note the green Server Running indicator at the bottom of WebLogic Workshop
(Figure 4-67).
Server Running
Indicator
2. Run the Portal by clicking the Run icon on the Toolbar (Figure 4-68).
Run Icon
Note: Clicking this icon causes the debugger to run before the portal renders.
The portal opens in a test browser (Figure 4-69).
1. In the Find Customer Portlet, enter XYZ Systems in Company and Bob Smith in Name.
2. Click Submit.
All three portlets refresh with Bob Smith’s customer and order information (Figure 4-70).
Backing files allow you to programatically add functionality to a portlet by implementing (or
extending) a Java class, which enables preprocessing (for example, authentication) prior to
rendering the portal controls. Backing files can be attached to portals either by using WebLogic
Workshop or coding them directly into a .portlet file.
This section is primer on backing files. It includes information on the following subjects:
z Desktops
z Books
z Pages
z Portlets
1. All init() methods are called on all backing files on an “in order” basis (that is, in the order
they appear in the tree). This method gets called whether or not the control (that is, portal,
page, book, or desktop) is on an active page.
2. Next, if the operation is a postback and the control (a portlet, page, or book) is on a visible
page, all handlePostbackData() methods are called. In other words if portlet is on a page
but its parent page is not active, then this method will not get called.
– If _nfpb="true" is set in the request parameter of any handlePostbackData()
methods called, raiseChangeEvents() is called. This method causes events to fire.
3. Next, all preRender() methods are called for all controls on an active (visible) page.
4. Next, the JSPs get called and are rendered on the active page by the
<render:beginRender> JSP tag. Rendering is stopped with the <render:endRender>
tag.
com.bea.netuix.servlets.controls.content.backing.AbstractJspBacking abstract
class. You only need to modify these files as necessary to implement the backing functionality
you desire.
Listing 5-1 is the backing file used in Establishing IPC by Using Custom and Page Flow Events
In this example, the AbstractJspBacking class is extended to provide the backing functionality
required by the portlet.
package backing;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.bea.netuix.events.Event;
import com.bea.netuix.events.CustomEvent;
import com.bea.netuix.servlets.controls.content.backing.AbstractJspBacking;
mySession.setAttribute("customerName", message);
<netuix:content>
<netuix:jspContent
backingFile="portletToPortlet.pageFlowSelectionDisplayOnly.menu.
backing.MenuBacking"
contentUri="/portletToPortlet/pageFlowSelectionDisplayOnly/menu/
menu.jsp"/>
</netuix:content>