JavaServer Faces 2.0 is specified by JSR-314. To write a portlet using JSF, it is required to have a 'bridge'. This software allows developers to write a portlet as if it was a JSF application.
JBoss Portlet Bridge implements the bridge specification. The branch 3.x supports JSF2 in a portlet.
The documentation of JBoss Portlet Bridge 3.x can be found here. If you have concern about versions, this page may help. At the time this section was validated, 3.1 was used.
There are two things necessary when building a JSF2 application into a portlet:
JSF and Portlet Bridge libraries must be available. (They are not bundled with the eXo Platform package).
Here is an excerpt of pom.xml:
<dependencies>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.14</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<scope>runtime</scope>
<version>2.1.14</version>
</dependency>
<dependency>
<groupId>org.jboss.portletbridge</groupId>
<artifactId>portletbridge-api</artifactId>
<version>3.1.2.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.portletbridge</groupId>
<artifactId>portletbridge-impl</artifactId>
<version>3.1.2.Final</version>
<scope>runtime</scope>
</dependency>
</dependencies>
Pay attention to the runtime
scope. This tells Maven to include the dependencies to WEB-INF/lib.
A portlet.xml
file is required and it must declare the portlet class as
javax.portlet.faces.GenericFacesPortlet
.
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
<portlet>
<portlet-name>jsf2portlet</portlet-name>
<portlet-class>javax.portlet.faces.GenericFacesPortlet</portlet-class>
<init-param>
<name>javax.portlet.faces.defaultViewId.view</name>
<value>/pages/main.xhtml</value>
</init-param>
<init-param>
<name>javax.portlet.faces.defaultViewId.edit</name>
<value>/pages/edit.xhtml</value>
</init-param>
<init-param>
<name>javax.portlet.faces.defaultViewId.help</name>
<value>/pages/help.xhtml</value>
</init-param>
<init-param>
<name>javax.portlet.faces.preserveActionParams</name>
<value>true</value>
</init-param>
<expiration-cache>0</expiration-cache>
<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 2.0 AJAX Portlet</title>
</portlet-info>
</portlet>
</portlet-app>
The initialization parameters are explained here.
A sample JSF2 portlet can be found at JPB project, or you can create it yourself in steps: JSF2 portlet example, Developer guide.