Home > Facelets, JSF, Java, Richfaces > JSF+Facelets+Richfaces Installation-Guide

JSF+Facelets+Richfaces Installation-Guide

Introduction:

Installing facelets together with richfaces is very simple. I used to develope web applications with JSF and its libraries like richfaces, Icefaces and so on. But I felt, my application have achieved a greater landmark only after implementing facelets. The reason is, facelets contains obliging features like templating(Similarly like struts), Composition components(Reuse can be achieved), also resolves the mismatch between JSF and JSP technologies(Eg: <jsp:param> tag cannot be used in JSF while using <jsp:include> tag) and so on. This article explains the installation of Richfaces and facelets with JSF.

Prerequisites:

  • IDE – Netbeans 6.x or Eclipse(Now Netbeans 6.7 provides the feature for creating facelets projects)
  • Tomcat 6.x or Glassfish
  • JDK 1.5 and above

Installing facelets can be accomplished by four steps in a web application project. If you are the one who use Netbeans 6.7 IDE which provides the features for creating facelet projects kindly skip the below step1 and step3 and just add the richfaces jars specified in the libraries and configure richfaces in web.xml. Others kindly follow the below steps,

Step1:

In step1, download and ensure that your projects WEB-INF/lib directory contains the below jar files.

Libraries:

  • commons-beanutils.jar
  • commons-collections.jar
  • commons-digester.jar
  • commons-logging.jar
  • el-ri.jar
  • jhighlight-1.0.jar
  • jsf-api.jar
  • jsf-facelets.jar
  • jsf-impl.jar
  • jstl.jar
  • richfaces-api-3.3.1.GA.jar
  • richfaces-impl-3.3.1.GA.jar
  • richfaces-ui-3.3.1.GA.jar

Step2:

Step2 clearly explains how to configure the web.xml for the facelet projects. Your web.xml file should contains the following configurations for the JSF+Facelets+Richfaces Installations.

web.xml configuration:


<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<context-param>
<param-name>com.sun.faces.verifyObjects</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.validateXml</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>facelets.SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<!-- Richfaces Configuration-->
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>wine</param-value>
</context-param>
<context-param>
<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
<param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

Step3:

Step3 explains the faces-config configurations.

faces-config configuration:

<application>
<view-handler>
com.sun.facelets.FaceletViewHandler
</view-handler>
</application>

Now you have completed the installation successfully and next you need create web pages in xhtml documents and you should specify the taglibs in XML namespaces instead of JSP taglibs.

Step4:

Create a xhtml document and your web page should contain the taglibs as stated in sample.xhtml, so that you can use the rich faces components together with facelets.

sample.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<body>
<h:form method="post">
<rich:panel>
<h:outputText value="Sample Text"></h:outputText>
</rich:panel>
</h:form>
</body>
</html>

Thatsall folks. I hope this article clearly explains the installation of Facelets and Richfaces with JSF. Some may say, this article is only about installation, but I want to get in to the action!!. Dont worry just follow the link Layouting and Dynamic include in Facelets , which will help you to construct templates and dynamic include using Facelets. If you find this article is quite useful, Dont forget to share with me by your valuable comments. Have a joyous code day.

  1. Heidi Lillebuen
    November 2, 2009 at 3:48 am | #1

    Thank you so much for a nice, quick way to present this. And the best: it works :) You saved me a lot of work.

  2. November 25, 2009 at 10:45 pm | #2

    I’m always searching for recent infos in the internet about this subject. Thanx.

  1. October 19, 2009 at 5:14 pm | #1
  2. November 10, 2009 at 9:41 pm | #2