Richfaces 4 quick tutorial

richfaces 4 tutorialThe RichFaces project is an advanced UI component framework for creating advanced JSF application leveraging rich component features and Ajax capabilities. Let's see how to get started with the RichFaces release 4.

 

 

At first download the final release 4.X.X of Richfaces framework from here.

 

The distribution when unpacked contains the following folders:

 

folderarchetypes Can be used to create a basic Richfaces application generated with  Maven
artifacts Contains Richfaces libraries
docs Contains the JavaDocs for Richfaces
examples Contains the Richfaces core demo suite

Creating your first Richfaces 4 application

In order to create a Richfaces application you have several option: you can either use Maven for picking up the correct libraries or manually configure your web application libs.

Using Maven to pick up Richfaces libs

For Maven-based projects configure you can simply add to your pom.xml Richfaces dependencies:


<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.richfaces</groupId>
            <artifactId>richfaces-bom</artifactId>
            <version>${richfaces.version}</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>
…
<dependency>
 <groupId>org.richfaces.ui</groupId>
 <artifactId>richfaces-components-ui</artifactId>
</dependency>
<dependency>
 <groupId>org.richfaces.core</groupId>
<artifactId>

Refer to JBoss's Maven Guide here for further details about JBoss's Maven repository

Configuring manually your Richfaces libs

If you want to configure manually Richfaces libraries in your project, you have to add to following jars in your WEB-INF/lib:

Library Where to find it
archiverichfaces-core-impl-4.0.0.Final.jar Richfaces core distribution
archiverichfaces-core-api-4.0.0.Final.jar Richfaces core distribution
archiverichfaces-components-ui-4.0.0.Final.jar Richfaces core distribution
archiverichfaces-components-api-4.0.0.Final.jar Richfaces core distribution
archivesac-1.3.jar Third-party lib. Get it here
archivecssparser-0.9.5.jar Third-party lib. Get it here
archiveguava-r08.jar Third-party lib. Get it here

The last step is configuring your web.xml to map your URL pattern with the Faces Servlet and a bare bone faces-config.xml which states you are using JSF 2.0 specification.

Here's WEB-INF/web.xml


<?xml version="1.0" encoding="ASCII"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
    <display-name>rich</display-name>
    <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>
</web-app>

And your WEB-INF/faces-config.xml


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

<faces-config
    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-facesconfig_2_1.xsd"
    version="2.1">

</faces-config>

</faces-config>