Portal Guide

CHAPTER 16

Using Portlets with JSP Pages

This chapter describes techniques for using portlets with JSP pages. It covers the following topics:

 
Top of page

Portlet tag libraries

exteNd Director provides the following tag libraries for using portlets with JSP pages:

Tag library

Description

PortalTag.tld

Provides custom tags for handling render and action URL requests, rendering portlet content, and styling portlet content on a JSP page.

For more information    For more information, see Adding portlets to JSP pages using custom tags.

portlet.tld

Implements the standard portlet tags specified by Java Portlet 1.0.

For more information    For more information, see Standard portlet tags.

 
Top of page

Adding portlets to JSP pages using custom tags

exteNd Director provides the following custom tags in WEB-INF\tag\PortalTag.tld for displaying portlets within JSP pages:

Custom tag

Description

renderPortlet

Renders portlet content within a JSP page

handlePortletAction

Handles all render and action URL requests issued to portlets on a JSP page

getThemeLink

Inserts the cascading style sheet (CSS) for the current portal theme into the JSP page

With these tags, you can add portlets to JSP pages using one or more of the following techniques:

NOTE:   The registration ID is the name you give a registered instance of a portlet, as described in Procedure for registering a portlet.

For more information    For information about the syntax of custom portlet tags in PortalTag.tld, see Portal Tag Library.

 
Top of section

Adding unique instances of portlets to a JSP page

Procedure To add unique instances of registered portlets to a JSP page:

  1. Add the tag library directive for PortalTag.tld to the top of your JSP page:

      <%@ taglib uri="/portal" prefix="portal" %>
    

    This directive makes the tags described in the PortalTag.tld file available to the page.

  2. Add the handlePortletAction tag under the tag library directive and before the <html> section:

      <%@ taglib uri="/portal" prefix="portal" %>
      <portal:handlePortletAction />
    
  3. Add the getThemeLink tag in the <head> section:

      <%@ taglib uri="/portal" prefix="portal" %>
      <portal:handlePortletAction />
      <html>
      <head>
         <portal:getThemeLink />
      </head>
    
  4. Add renderPortlet tags for each portlet you want to display on the page.

Example: JSP page renders content of two portlets

Here's an example of a JSP page that renders the content of two registered portlets: StockPortfolio and StockQuotePortlet:

  <%@ taglib uri="/portal" prefix="portal" %>
  <portal:handlePortletAction />
  <html>
  <head>
     <portal:getThemeLink />
  </head>
  <body>
  <table>
     <tr>
        <td>Stock Information Page</td>
     </tr>
     <tr>
        <td><portal:renderPortlet registrationID="StockPortfolio" /></td>
     </tr>
     <tr>
        <td><portal:renderPortlet registrationID="StockQuotePortlet" /></td>
     </tr>
  </table>
  </body>
  </html>

 
Top of section

Adding multiple instances of the same portlet to a JSP page

Procedure To add multiple instances of the same registered portlet to a JSP page:

  1. Follow the steps in the procedure Adding unique instances of portlets to a JSP page.

  2. Use a renderPortlet tag for each instance of the same portlet.

  3. In each renderPortlet tag, set the pageNamespace attribute to a unique string.

    NOTE:   The pageNamespace attribute is used to differentiate portlets with identical registration IDs that reside on the same page—and to allow each portlet to maintain its own session state.

Example: JSP page renders content of multiple instances of same portlet

Here's an example of a JSP page that renders the content of three instances of the same registered portlet:

  <%@ taglib uri="/portal" prefix="portal" %>
  <portal:handlePortletAction />
  <html>
  <head>
     <portal:getThemeLink />
  </head>
  <body>
  <table>
  <tr>
     <td>Stock Portfolio 401K</td>
     <td>Stock Portfolio Roth IRA</td>
     <td>Stock Portfolio SEP IRA</td>
  </tr>
  <tr>
     <td>portal:renderPortlet registrationID="StockPortfolio" pageNamespace="401K" /></td>
     <td>portal:renderPortlet registrationID="StockPortfolio" pageNamespace="Roth" /></td>
     <td>portal:renderPortlet registrationID="StockPortfolio" pageNamespace="SEP" /></td>
  </tr>
  </table>
  </body>
  </html>

 
Top of section

Adding pageflow portlets to a JSP page

Procedure To add pageflow portlets to a JSP page:

  1. Follow the steps in the procedure Adding unique instances of portlets to a JSP page or Adding multiple instances of the same portlet to a JSP page.

  2. Add the following namespaces in the <html> element of the page:

    1. xmlns:ev="http://www.w3.org/2001/xml-events

    2. xmlns:xforms="http://www.w3.org/2002/xforms

Example: JSP page renders content of pageflow portlet that uses XForms

  <%@ taglib uri="/portal" prefix="portal" %>
  <portal:handlePortletAction />
  <html xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms">
  <head>
     <portal:getThemeLink />
  </head>
  <body>
  <table>
     <tr>
        <td>Human Resources: Benefits Data</td>
     </tr>
     <tr>
        <td><portal:renderPortlet registrationID="MyHRDatabasePageflow" /></td>
     </tr>
  </table>
  </body>
  </html>

 
Top of page

Standard portlet tags

exteNd Director implements the standard portlet tags specified by Java Portlet 1.0. The standard Portlet Tag Library enables JSPs that are included from portlets to have direct access to portlet-specific elements and portlet functionality.

The standard portlet tags are:

Tag

Description

defineObjects

Defines variables for accessing portlet objects such as render request and render response

actionURL

Triggers an action request to the current portlet with supplied parameters

renderURL

Triggers a render request to the current portlet with supplied parameters

param

Defines a parameter that may be added to a actionURL or renderURL.

namespace

Produces a unique value for the current portlet

To use standard portlet tags, add the following tag library directive to the top of your JSP page:

  <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>

For more information    For more information about the standard Portlet Tag Library, refer to the Java Portlet 1.0 specification, available from the Java Community Process Web site at:

  http://jcp.org/aboutJava/communityprocess/final/jsr168/index.html


Copyright © 2004 Novell, Inc. All rights reserved. Copyright © 1997, 1998, 1999, 2000, 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved.  more ...