Communities
|
Social Applications
Networks
Support
|
|
C-Level Executives
Other Roles
|
|
Support
Education
Partner
Other Tasks
|
|
| By Deepak Gothe and Marina Sum, June 26, 2007 |
|
| |
|
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:
| |
| - | Design | ||||
| - | Binary | ||||
| - | Compliance With JSR 168 | ||||
|
|||||
| - | Tag Library | ||||
| - | References | ||||
| |
| |
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:
| |
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.
Process
Modify your JSF application as follows:
jsf-portlet.jar) and copy it to the
WEB-INF/lib directory of the JSF application.
portlet.xml file in the
WEB-INF directory of the application. In that file
portlet-class to
com.sun.faces.portlet.FacesPortlet.
com.sun.faces.portlet.INIT_VIEW to the first page of the JSF application, for example,
greetings.jsp.
portlet.xml file in the sample application (
guessnumberportlet), described in the next subsection:
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
<portlet>
<description>JSF GuessNumber Portlet</description>
<portlet-name>guessnumber</portlet-name>
<display-name>JSF GuessNumber Portlet</display-name>
<!-- You must use this Portlet implementation class -->
<
portlet-class>com.sun.faces.portlet.FacesPortlet
</portlet-class>
<!-- This is a required parameter and must point to the first page of the JSF application -->
<init-param>
<description>Portlet init view page</description>
<name>com.sun.faces.portlet.INIT_VIEW</name>
<value>/greeting.jsp</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
<portlet-mode>EDIT</portlet-mode>
<portlet-mode>HELP</portlet-mode>
</supports>
<portlet-info>
<title>GuessNumber Portlet</title>
<short-title>guessNumber</short-title>
</portlet-info>
</portlet>
</portlet-app>
|
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:
<init-param>
<description>Portlet edit page</description>
<name>com.sun.faces.portlet.INIT_EDIT</name>
<value>/edit.jsp</value>
</init-param>
|
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:
<navigation-rule>
<from-view-id>/edit.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/greeting.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/edit.jsp</from-view-id>
<navigation-case>
<from-outcome>cancel</from-outcome>
<to-view-id>/greeting.jsp</to-view-id>
</navigation-case>
</navigation-rule>
|
success on the final page must point to the first view page.
cancel to the first view page.
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:
<init-param>
<description>Portlet init help page</description>
<name>com.sun.faces.portlet.INIT_HELP</name>
<value>/help.jsp</value>
</init-param>
|
<html>,
<head>, and
<body> tags.
forward and
redirect. The new page will replace the existing portal pages.
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
|
| |
The tag library (
jsf-portlet.tld) contains tags for the JSF components in the portal environmentcomponents 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="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/portlet/components" 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. --%> <f:view> <p:portletPage> ..................... ..................... </p:portletPage> </f:view> |
You can find the tag library at these two locations:
jsf-portlet/src/java/com/sun/faces/portlet directory in the source
META-INF directory in the Java archive (
jsf-portlet.jar)
| |

