Surfacing Applications with Portlets

 <  Day Day Up  >  

Surfacing Applications with Portlets

Remember that the goal of portlets is to display content for applications. The idea of bringing forward content from an application is known as surfacing . Portlets are developed as a single JSP file or a Page Flow. You can also create portlets from controls.

Creating a Portlet from a JSP

Portlets, which are used to display content in a portal application, have a definition configured in Workshop that associates properties with content. To add a portlet to a portal application, drag a Web resource (a JSP or JPF file) onto a page, as shown in Figure 12.5.

Figure 12.5. Adding a JSP resource as a portlet.

graphics/12fig05.gif

Dragging the Web resource launches the Portlet Wizard, where you can configure a title bar for a portlet. Title bars are optional parts of a portlet, and in some cases, you might not want to display them. Perhaps the portlet is simply going to display an image and, therefore, would look strange with a title bar around it.

SHOP TALK : USING WEBLOGIC PORTAL'S ORGANIZATIONAL FEATURES TO DISPLAY CONTENT

Most people probably associate portal applications with the myYahoo! experience, for example. This kind of portal works well if you want users to be able to decide what kind of content they want to see and how they would like to see it. But what if that's not the case? To that end, I might decide that users shouldn't be allowed to minimize or maximize pages, for example.

Remember, WebLogic Portal is a framework to display content. When users aren't allowed to customize a portal's appearance, WebLogic Portal is used for its organizational and administrative capabilities. Additionally, I would deploy my portlets without title bars and could create my own look and feel to have pages and books displayed as a navigation bar. To the users of my Web site, it would look the same as any other site they visit on the Web.

An example of this type of application is a retail site. People are accustomed to seeing all this information as though it were one continuous page, not a collection of smaller building blocks. Through the use of code, I could create portlets for a catalog, a shopping cart, and best-selling items. When these portlets are deployed without title bars, they would give the impression that they're one page.


You can edit title bar properties later in Workshop's Property Editor. Table 12.3 lists the title bar properties, all of which are optional.

Table 12.3. Title Bar Properties

PROPERTY

DESCRIPTION

Icon URL

A URL to display an image in the title bar.

Help URL

A URL to a page that explains to users what the portlet does.

Edit URL

A URL to a page that enables users to add to the portlet. For example, in a portlet that keeps track of stocks, the Edit page would allow users to add stocks to their watch list.

Can Minimize

Minimizing a portlet shrinks the content to display only the title bar.

Can Maximize

Maximizing a portlet displays the portlet's content between the portal's header and footer.

Can Delete

Allowing the portlet to be deleted means that users can remove the portlet from their view of the portal.

Creating a Portlet from a Page Flow

Page Flows are another Web resource that can be added as a portlet. As discussed in Chapter 4, Page Flows are used to organize Web applications. They can also be used to create more complex portlets. To add a Page Flow to a portlet, drag the JPF file from the directory structure to the page where you might want to add the portlet. Dragging this file starts the same Portlet Wizard. Figure 12.6 shows the desktop with the portlets added. Notice that the BuyChips application from Chapter 4 is used in this Page Flow example.

Figure 12.6. A desktop with portlets added.

graphics/12fig06.gif

Creating a Portlet from a Control

You might be thinking that adding portlets to a portal application is easy so far, and that's good. You might also be wondering how you can access more complex applications in a portal. For example, you might have a legacy application with a Web service front end, or you might want a way for users to log in so that you can add personalization services. The example used in this chapter demonstrates adding login functionality to a portal application.

WebLogic Portal provides a control to allow developers to log people in and out of an application. The way to use this control for the portal application is to create a Page Flow from it. Then you can easily add it to the portal. By convention, a portlets directory has been added in the application. Right-click on this directory, and select the option to create a new Page Flow. Name the Page Flow Login , and click Next. Select the option to create a Page Flow from a Java control; the control you want to select is the User Login Control. The next wizard page prompts you to select which methods of the control should be exposed in the Page Flow; for the login portlet, you want the login and logout methods. You're almost done, but often when you're creating a Page Flow from a control, there's some cleanup to be done.

Listing 12.1 shows the form that's generated for logging in to the application.

Listing 12.1. The Login Form Generated by Workshop
 <netui:form action="login">             <table class="tablebody">                 <tr class="tablebody">                     <td>Password:</td>                     <td>                         <netui:textBox dataSource="{actionForm.password}"/>                     </td>                 </tr>                 <tr class="tablebody">                     <td>Username:</td>                     <td>                         <netui:textBox dataSource="{actionForm.username}"/>                     </td>                 </tr>                 <tr>                     <td valign="top">                         Request:                     </td>                     <td class="prompt">                       To-Do: To create an input form for a complex data type                              (javax.servlet.http.HttpServletRequest),                              open the page editor and add netui input tags                              for the relevant fields of the class.                       <!---Fill this form with fields such as :xxx                       <netui:textBox dataSource="{actionForm.request.xxx}" />-->                     </td>                 </tr>             </table>             <br/>&nbsp;             <netui:button value="Submit" type="submit"/> 

The most important issue to note is that a form element was created for the HTTPRequest object that's required for the login() method. HTTPRequest is a complex type and cannot be passed in through a form, so you need to edit the login.jsp file the form is in and the LoginController.jpf file where HTTPRequest is passed in to the login() method. In Listing 12.1, you can simply remove the form element from the JSP. Listing 12.2 shows the login() method from LoginController.jpf .

Listing 12.2. The Login Method from LoginController.jpf
 public Forward login( LoginForm aForm )throws Exception {         com.bea.p13n.usermgmt.profile.ProfileWrapper var =             myControl.login( aForm.username, aForm.password, aForm.request );         getRequest().setAttribute( "results", var );         return new Forward( "success" );     } 

Notice that when the login() method is carried out, the aForm.request variable is passed in. This variable doesn't exist because you cannot pass in the HTTPRequest object via a form. What's the solution? Simply replace aFrom.request with the actual request by using this.getRequest() . This supplies the User Login Control with the request it needs to log in the user. You need to take similar steps for the logout() method and whenever you create a Page Flow from a control. Figure 12.7 shows the completed application with three portlets: one from a JSP file and two from Page Flows.

Figure 12.7. The portal application with three portlets.

graphics/12fig07.gif

 <  Day Day Up  >  


BEA WebLogic Workshop 8.1 Kick Start
BEA WebLogic Workshop 8.1 Kick Start: Simplifying Java Web Applications and J2EE
ISBN: 0672326221
EAN: 2147483647
Year: 2004
Pages: 138

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net