Professional Documents
Culture Documents
JSF Portlet: All Rights Reserved
JSF Portlet: All Rights Reserved
JSF Portlet: All Rights Reserved
Objective
The goal of this tutorial is to create a Java
Server Faces (JSF) Portlet within Liferay
1. Define the portlet
portlet.xml
liferay-portlet.xml
2. Define the page flow and layout
faces-config.xml
3. Create the JSP
index.jsp
Directory Structure
Starting with Liferay version 4.2 we've made
it possible to develop portlets in a
deployable *.war format.
This tutorial will adhere to the specs of this
new feature.
Directory Structure
1) Go to:
http://www.liferay.com/web/guest/downloads/samples
Directory Structure
Configuration files (*.xml) are located in this
directory:
\ext\portlets\library_jsf_portlet.war\WEBINF
JSPs will be placed in this directory:
\ext\portlets\library_jsf_portlet.war
web.xml
The web.xml is a standard web application
descriptor file that is required by any J2EE
servlet container such as Tomcat. In this
case we have a *.war file that is being
deployed onto Tomcat, and the web.xml
file describes the portlet application.
This configures our JSF implementation
as well as the necessary hooks into the
portal.
web.xml
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>library_jsf_portlet</display-name>
<context-param>
<param-name>company_id</param-name>
<param-value>liferay.com</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.faces.application.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<listener>
<listener-class>com.liferay.portal.kernel.servlet.PortletContextListener</listenerclass>
</listener>
<listener>
<listenerclass>org.apache.myfaces.webapp.StartupServletContextListener</listenerclass>
</listener>
<servlet>
<servlet-name>library_jsf_portlet</servlet-name>
<servlet-class>com.liferay.portal.kernel.servlet.PortletServlet</servlet-class>
<init-param>
<param-name>portlet-class</param-name>
<paramvalue>com.sample.jsfmyfaces.portlet.MyFacesGenericPortlet</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet>
<servlet-name>FacesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>library_jsf_portlet</servlet-name>
<url-pattern>/library_jsf_portlet/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>http://java.sun.com/portlet</taglib-uri>
<taglib-location>/WEB-INF/tld/liferayportlet.tld</taglib-location>
</taglib>
</web-app>
portlet.xml
The portlet.xml is the portlet descriptor per
the JSR-168 spec.
portlet.xml
<?xml version="1.0"?>
<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>
<portlet-name>library_jsf_portlet</portlet-name>
<display-name>library_jsf_portlet</display-name>
<!--<portlet-class>org.apache.myfaces.portlet.MyFacesGenericPortlet</portletclass>-->
<portlet-class>com.sample.jsfmyfaces.portlet.MyFacesGenericPortlet</portletclass>
<init-param>
<name>default-view</name>
<value>/index.jsp</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
</supports>
<portlet-info>
<title>Library JSF Portlet</title>
<short-title>Library JSF Portlet</short-title>
<keywords>Library JSF Portlet</keywords>
</portlet-info>
<security-role-ref>
<role-name>guest</role-name>
</security-role-ref>
<security-role-ref>
<role-name>power-user</role-name>
</security-role-ref>
<security-role-ref>
<role-name>user</role-name>
</security-role-ref>
</portlet>
</portlet-app>
liferay-portlet.xml
The liferay-portlet.xml contains Liferayspecific configurations
liferay-portlet.xml
<?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet
Application 4.1.0//EN" "http://www.liferay.com/dtd/liferay-portletapp_4_1_0.dtd">
<liferay-portlet-app>
<portlet>
<portlet-name>library_jsf_portlet</portlet-name>
<instanceable>true</instanceable>
</portlet>
<role-mapper>
<role-name>administrator</role-name>
<role-link>Administrator</role-link>
</role-mapper>
<role-mapper>
<role-name>guest</role-name>
<role-link>Guest</role-link>
</role-mapper>
<role-mapper>
<role-name>power-user</role-name>
<role-link>Power User</role-link>
</role-mapper>
<role-mapper>
<role-name>user</role-name>
<role-link>User</role-link>
</role-mapper>
</liferay-portlet-app>
liferay-display.xml
The liferay-display.xml configured display
settings such as which Liferay category
this portlet belongs to.
liferay-display.xml
<?xml version="1.0"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display
4.0.0//EN" "http://www.liferay.com/dtd/liferaydisplay_4_0_0.dtd">
<display>
<category name="category.test">
<portlet id="library_jsf_portlet" />
</category>
</display>
index.jsp
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"
%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"
%>
<f:view>
<h1>
<h:outputText value="Simple JSF Portlet" />
</h1>
</f:view>
build.xml
<target name="compile">
<antcall target="compile-module">
<param name="module.name"
value="library_jsf_portlet" />
</antcall>
</target>
<target name="clean">
<antcall target="clean-module">
<param name="module.name"
value="library_jsf_portlet" />
</antcall>
</target>
Final Steps
1. Restart Tomcat
2. Open up a new browser and type
http://localhost:8080
LOGIN: test@liferay.com
PASSWORD: test
3. Click Add Content Test
4. Click Library JSF Portlet
Revision History
Edward Shin
Jerry Niu
Jerry Niu
James Min
Ivan Cheung