Friday September 07, 2007
Running Woodstock JSF Components in Portlet environment
Running Woodstock JSF Components in Portlet environment
Overview
This document presents a 'brief' overview on how Woodstock components could be used within a portal server. The Netbeans 5.5 with partial portal pack installed ( complete portal pack is available for NB 6.0) was used to develop and interactively debug the portlets, and the corresponding Netbeans projects with the sample files are available throughout the document. Neither Netbeans nor portal pack are required in order to accomplish the goal, and information on such can be easily omitted within this document.
Known Issues
JSF Portlet Bridge JSF Portlet Bridge https://jsfportletbridge.dev.java.net/ is used as JSF-portlet harness. Currently it does not support JSF Extensions ( DynaFaces) which in turn represents a technology of choice for woodstock Ajax functionality. An issue https://jsfportletbridge.dev.java.net/issues/show_bug.cgi?id=17 has been filed. Thus woodstock Ajax functionality cannot currently be enabled with the use of JSF Porltet Brdige. Currently such support is expected with the jsf-portlet-bridge implementation of JSR301.
Deployment choices
Portal server and portal container are provided and can be deployed in multiple implementations. For example, few of the options include:
Sun Portal Server
OpenPortal Server
GlassFish server + PortletContainer
Sun Application Server + PortletContainer [chosen]
Tomcat + PortletContainer ( Supported Tomcat version is 5.5 does not support JSF 1.2 though)
etc, etc.
Current documented exercise has chosen the option of Open Porltet Container installed on the top of Sun Application Server 9
Steps
Install portal server(or container + web server)
[optional] Create test portlet
[optional] Create and run-verify sample JSF application ( not portlet yet)
Obtain and install JSFPortletBridge
Modify application from step 2 to accommodate for portlet specifics.
Deploy and Run the portlet.
Step 1. Install portlet container ( or portal server)
Download PortletContainer https://portlet-container.dev.java.net/public/Download.html#Instructions_to_install_Portlet_ and follow the instructions at the end of the page on installation. For example, the command on Windows may look something like this:
java -jar portlet-container-configurator.jar C:\Sun\AppServer\ C:\Sun\AppServer\domains\domain1
verify that portlet container is installed properly by browsing to http://<appserver-host>:<app-server-port>/portletdriver. You should see something like this:

Step 2. [optional] Create Test Portlet
Download and install Netbeans portal pack
You can build portlet by hand, or use Netbeans portal pack (http://portalpack.netbeans.org/download.html), which provides means to quickly build portlets.
Create Test Portlet project
Create new portal project named, say, portlet1

Create new portlet
File/New JSR 168 Portlet

build the portlet1.war file ( project/build) and deploy this war file interactively into the portlet container.
ensure portlet is running:

Sample project attached:
Step 2 results
Portlet container is running and simple portlets are deployable.
Step 3. Create Sample JSF application
Create sample JSF application.This application will be converted to the portlet at later stages, and thereby I named it 'jsfPortlet'.
Sample project attached:
Step 4. Install JSF-Portlet Bridge
Now that we are sure that portlets are running, the next step is to install a JSF-portlet bridge.
Download bridge https://jsfportletbridge.dev.java.net/ ( download page https://jsfportletbridge.dev.java.net/public/Download.html)
add jsf-portlet.jar ( the bridge library) to your application. Within Netbeans, one way to add it would be to create a JsfPortletBridge library ( Tools/Library Manager) , and add it to the “Packaging Section” of the build:

modify web.xml of your application to NOT contain a reference to PARTIAL lifecycle ( see issue https://jsfportletbridge.dev.java.net/issues/show_bug.cgi?id=17 ) - comment out the LIFECYCLE_ID section as below:
Step 5. Convert JSF application to JSF portlet
Continuing working on jsfPortlet project, there are some changes that have to be done to JSP pages as well as configuration files. Let's keep the original JSF application's JSP page Page1.jsp intact, and make a clone of it Page1_portlet.jsp. Page1_portlet.jsp is the portlet jsp that will take all the changes.
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<!--
<init-param>
<param-name>javax.faces.LIFECYCLE_ID</param-name>
<param-value>com.sun.faces.lifecycle.PARTIAL</param-value>
</init-param>
-->
<load-on-startup>1</load-on-startup>
</servlet>
read the “Converting JSF-based Applications to JSF Aware Portlets” document at https://jsfportletbridge.dev.java.net/DeployingJSFPortlet.html
additionally modify your JSP pages to contain webui:themeLinks
<webuijsf:themeLinks ajaxify="false" id="theme_1"/>
Now Page1_portlet.jsp would look something like this:
<?xml version="1.0" encoding="UTF-8"?>
<jsp:root version="2.1" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:webuijsf="http://www.sun.com/webui/webuijsf">
<jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
<f:view>
<webuijsf:page binding="#{Page1.page1}" id="page1" >
<webuijsf:themeLinks ajaxify="false" id="themeId"/>
<webuijsf:form binding="#{Page1.form1}" id="form1">
<webuijsf:messageGroup binding="#{Page1.messageGroup1}" id="messageGroup1" style="position: absolute; left: 216px; top: 8px; width: 264px; height: 48px"/>
<webuijsf:textField
id="tf"
text="Dmitry"
label="Name"
columns="20"
/>
<p>
<webuijsf:button primary="true" id="submitButton" text="Submit" actionExpression="#{FieldBean.submitForm}"/>
</p>
</webuijsf:form>
</webuijsf:page>
</f:view>
</jsp:root>
And portlet.xml:
<?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 Sample Portlet</description>
<portlet-name>jsfsampleportlet</portlet-name>
<display-name>JSF Sample 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>/Page1_portlet.jsp</value>
</init-param>
<init-param>
<description>Portlet init edit page</description>
<name>com.sun.faces.portlet.INIT_EDIT</name>
<value>/Page1_portlet.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>JSF Sample Portlet</title>
<short-title>jsfsampleportlet</short-title>
</portlet-info>
</portlet>
</portlet-app>
build the project, and deploy the war into the portlet container. Here is how our sample portlet looks like:

and with 2nd instance of the same portlet plus some other portlets on one page:

Note that once the jsf-portlet.jar became part of the build, its LifecycleImpl is taking over, and the application will not be able to run as regular JSF application any more.
Other references
Satya's post "Build JSF Portlet with NetBeans Visual Web Pack and NetBeans Portal Pack"
http://portalpack.netbeans.org/UG_PortletContainerPlugin.html
Posted at 01:22PM Sep 07, 2007 by Dmitry Kushner in Sun | Comments[6]
hgkhjhjh
Posted by yjghgkjh on October 03, 2007 at 07:57 AM MDT #
dsqdqsdqs
Posted by 88.166.161.7 on November 10, 2007 at 02:51 PM MST #
Hi there,
Thanks for providing convert an existing JSF web application to Portlet. But I can still do it well. Could you please attach an converted application to me !
Thank you very much.
Regard,
NVSANG.
Posted by nvsang on November 24, 2007 at 08:52 PM MST #
Dmitry, i can't make it work with woodstock only ui componetns, works fine. How about a sample project?
my google search's point only to you blog, it seams where are the only ones in this line of work...and Satya's Blog...
is there any one out there!
Posted by Nuno Anjos on February 05, 2008 at 08:36 AM MST #
The JSF/Portlet bridge has been patched to resolve the AJAX issue. Can this be updated?
Posted by Jason Williams on March 28, 2008 at 12:39 PM MDT #
asdsdasd
Posted by 200.32.2.218 on May 11, 2009 at 02:05 PM MDT #