Open-Source Portal Initiative at Sun, Part 5: JavaServer Faces Technology-Based Portlet Bridge

By Deepak Gothe and Marina Sum, June 26, 2007  


OpenPortal is Sun's open-source project for Sun Java System Portal Server, a key component of the Sun Java Enterprise System stack.
Java Specification Request (JSR) 168: Portlet SpecificationOpenPortalJSF Portlet Bridge Project

This article, the fifth in a series, describes the design and binary of the Portlet Bridge, the procedure for modifying JSF applications to comply with JSR 168, as illustrated by a sample application, and the Portlet Bridge's tag library.

See also the other four parts of this series:

Compliance With JSR 168
Sample Application
Tag Library

The JSF Portlet Bridge provides portlet-specific implementation for the following classes or interfaces of the JSF Framework:

javax.faces.context.FacesContextFactory   javax.faces.context.FacesContext
javax.faces.lifecycle.LifecycleFactory   javax.faces.lifecycle.Lifecycle
javax.faces.context.ExternalContext   javax.faces.application.ViewHandler

As documented in the JSF specification, the preceding six classes in the JSF Portlet Bridge play the same role in the portlet environment as they do in the servlet environment, as follows:

In the portlet environment, when you call a portlet's render() method, you execute RenderResponsePhase of the JSF life cycle. When you call the action() method, you execute the other four phases: RestoreViewPhase, ApplyRequestValuesPhase, ProcessValidationsPhase, and UpdateModelValuesPhase. Since you can call render() without the action being performed on the portlet, the JSF Portlet Bridge manages multiple render requests by storing the Faces View in the portlet session during the action life cycle and retrieving it during the render life cycle of the portlet.


Because the JSF 1.1 and 1.2 releases are significantly different, the JSF Portlet Bridge binary has two versions, each supporting a JSF release:

  • JSF Portlet Bridge 1.1 — Supports JSF 1.1. If the Web container on which the Portlet Container is running does not support JSF technology or supports JSF 1.1 only, use this 1.1 binary.

    To deploy JSF technology-based applications as portlets in Sun Java System Portal Server 7 or Pluto, the reference implementation of the Java Portlet Specification, use this 1.1 binary.
  • JSF Portlet Bridge 1.2 — Supports JSF 1.2. If the Web container on which the portlet container is deployed supports JSF 1.2, use this 1.2 binary.

    To deploy JSF technology-based applications as portlets in OpenPortal Portlet Container, which runs on GlassFish, use this 1.2 binary.
Compliance With JSR 168

To enable a JSF application to comply with JSR 168, modify the application before running it as a portlet. The portlet framework requires a deployment descriptor and imposes restrictions on the markup fragment. That framework also introduces the concept of three modes: VIEW, EDIT, and HELP, all supported by the JSF Portlet Bridge.

Modify your JSF application as follows:

  1. Download the appropriate JSF Portlet Bridge binary ( jsf-portlet.jar) and copy it to the WEB-INF/lib directory of the JSF application.
  2. Add a deployment descriptor for the portlet by creating a portlet.xml file in the WEB-INF directory of the application. In that file—

    1. Set portlet-class to com.sun.faces.portlet.FacesPortlet.
    2. Point the portlet parameter com.sun.faces.portlet.INIT_VIEW to the first page of the JSF application, for example, greetings.jsp.

    Here is the content of the portlet.xml file in the sample application ( guessnumberportlet), described in the next subsection:

    <?xml version="1.0" encoding="UTF-8"?>
    <portlet-app xmlns=""
    version="1.0" xmlns:xsi=""
            <description>JSF GuessNumber Portlet</description>
            <display-name>JSF GuessNumber Portlet</display-name>
                             <!-- You must use this Portlet implementation class -->
                              <!-- This is a required parameter and must point to the first page of the JSF application -->
                <description>Portlet init view page</description>
                <title>GuessNumber Portlet</title>
  3. Set the EDIT capability for the JSF portlet:

    1. In the portlet.xml file, point the portlet parameter com.sun.faces.portlet.INIT_EDIT to the edit page (for example, edit.jsp) of your portlet. See this example:

          <description>Portlet edit page</description>
    2. In the faces-config.xml file, set the navigation rule so that when EDIT is successful or cancelled, the <to-view-id> tag points to the first view page (for example, greetings.jsp) of your portlet, that is, the page tagged com.sun.faces.portlet.INIT_VIEW. See this example:

    Note the following:

    • The Edit page can also have a navigation rule. However, success on the final page must point to the first view page.
    • To give the user the choice of cancelling EDIT mode and return to VIEW mode, set up a a Cancel button on the Edit page. Here, point cancel to the first view page.
  4. Set the HELP capability for the JSF portlet: In the portlet.xml file, point the portlet parameter com.sun.faces.portlet.INIT_HELP to the Help page (for example, help.jsp) of your portlet. See this example:

        <description>Portlet init help page</description>
  5. Revise the JSP pages:

    1. Delete the <html>, <head>, and <body> tags.
    2. Update forward and redirect. The new page will replace the existing portal pages.

    Note: Avoid coding in the JavaScript scripting language: Portlets only minimally support client-side scripts such as those in JavaScript.
  6. Deploy the Web archive (WAR) file to your portal server.

Sample Application
As an illustration, here is a sample application, compressed as a ZIP file. Download the guessnumberportlet.war file and then deploy and run it in the OpenPortal Portlet Container.

Figure 1 shows the GuessNumber Portlet in the OpenPortal Portlet Container.

Figure 1: GuessNumber Portlet

To display the Edit page, as shown in Figure 2, click the Edit icon, denoted by a pen.

Figure 2: Edit Window

To display the Help page, as shown in Figure 3, click the Help icon, denoted by a question mark.

Figure 3: Help Page

Tag Library

The tag library ( jsf-portlet.tld) contains tags for the JSF components in the portal environment—components that are not part of the standard JSF specification. To have multiple instances of the same portlet reside on the same portal page, embed the portlet's JSF tags within a tag. Here is the syntax:

<%@ taglib uri="#" prefix="h" %>
<%@ taglib uri="#" prefix="f" %>
<%@ taglib uri="#" prefix="p" %>

See this example:

Embed JSF tags within portletPage tag to enable multiple instances of this portlet to reside on
the same portal page.


You can find the tag library at these two locations:

  • The jsf-portlet/src/java/com/sun/faces/portlet directory in the source
  • The META-INF directory in the Java archive ( jsf-portlet.jar)
Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Your email address (no reply is possible without an address):
Sun Privacy Policy

Note: We are not able to respond to all submitted comments.
Left Curve
Java SDKs and Tools
Right Curve
Left Curve
Java Resources
Right Curve
Java 8 banner (182)