How to add RichFaces 4.x to maven based project

This article will walk you through the steps needed to use RichFaces in a Maven build environment.  RichFaces 4 artifacts are available via maven central.  Should you wish to use SNAPSHOT builds (which are not published to maven central), refer to this article on configuring Maven to use a JBoss repository.

 

 

Managing Dependency Versions - the RichFaces BOM

First you should add richfaces-components-bom to your dependency-management section of your pom.xml. That should be done in order to have all the runtime dependencies with versions for the specified release.

 

    <properties>
        <org.richfaces.bom.version>4.1.0.Final</org.richfaces.bom.version>
        ...
    </properties>

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


What is a BOM?

BOM's are maven pom.xml files that specify the versions of all runtime dependencies for a given module.  So by importing this BOM, you are specifying the versions of the dependencies required to use RichFaces, but not (yet) specifying the dependencies themselves.

 

To understand the "Bill of Materials" (BOM) concept more check out:

 

RichFaces Dependencies

 

Next you will need to add richfaces-components-ui and richfaces-core-impl dependency to your project dependencies sections.

 

    <dependency>
        <groupId>org.richfaces.ui</groupId>
        <artifactId>richfaces-components-ui</artifactId>
    </dependency>
    <dependency>
        <groupId>org.richfaces.core</groupId>
        <artifactId>richfaces-core-impl</artifactId>
    </dependency>

 

All other dependencies will be fetched transitivelly.

 

A couple of things to note:

  • As you can see from the last code snippet - you do not need to specify the version for the dependencies, it's defined in BOM file we specified above.
  • Additional are dependencies for some features such as a4j:push, and the CDK.  See the respective wiki pages for details on adding those dependencies
  • JBoss AS 7 provides a means to selectively expose its internal libraries for aplication use, reducing the number of transient dependencies that must be included. 

 

Ready to use RichFaces in your project

With the above dependencies included in your pom file, you are now ready to makes use of RichFaces components in your application.  Simply add the following namespace definitions to your facelet file:

 

 

RichFaces samples - Import and Deployment in Jboss Tools

  • Checkout sources from https://svn.jboss.org/repos/richfaces/trunk/examples/
  • Execute mvn eclipse:eclipse from the root folder of example.
    • some examples supports different profiles(e.g. richfaces-showcase and core demo supports jee6 build for Jboss or gae for GAE compatible build). So in order to import sample for JEE 6 deployment add -P jee6 to the command line.
  • Import project as "Existent project" using Eclipse import project wizard
  • Add M2_REPO variable to Eclipse Class Path variables and point it to your local repository.
  • After project successfully built - add it to server from server view
  • run server and check application in browser.