Installing JSF 2.2 on JBoss AS 7

In this tutorial we will demonstrate how to install the JSF 2.2 API (part of the Java EE 7 specification) on JBoss AS 7.

Java EE 7 is almost on the way, featuring several interesting new features. After some changes, the JSF 2.2 specification will include the following so-called Big Tickets:

  • Sensible HTML 5 support  –
  • Faces Flow
  • Stateless views
  • Resource library contracts

Faces flow is the most interesting feature of JSF 2.2 which allows defining page flow navigation by the use of simple CDI annotations such as @FlowScoped which eletcs a bean to be considered as part of a specified flow.
(A remarkable detail is that JSF 2.2 thus introduces a dependency on CDI here, which might be indicative of JSF moving closer to CDI for other aspects as well)

The current release of JBoss AS 7.1.1 and the EAP 6.1 counterpart are based on JSF 2.1, however, due to the modular kernel of JBoss AS 7 is pretty simple to upgrade the JSF libraries.

At first let’s get the JSF 2.2 libraries. At the time of writing a 2.2.0 SNAPSHOT version of JSF Api and implementation (Mojarra) is available on the Maven’s Nexus repository:
As you can see from these pictures, you need to pickup both the core API and its implementation:

jsf 2.2 tutorial java ee 7
jsf 2.2 tutorial java ee 7

Once downloaded, we will install these modules on the application server.

#1 Option Replace the current JSF 2.1 Libraries
You need to copy these two JAR files into the modules installed on the application server:

  • modules/com/sun/jsf-impl/main for the implementation
  • modules/javax/faces/api/main for the API

and modify the resource-root path accordingly in each module.xml:

<resource-root path="jsf-impl-2.2.0-20130322.075047-259.jar"/>
<resource-root path="jsf-api-2.2.0-20130322.075010-270.jar"/>

Besides this, you need to state explicitely the reference to JSF implementation into the JSF api’s module.xml

<module name="com.sun.jsf-impl"/> 

#2 Add one more slot for your JSF 2.2 Api
As you might know, the AS7 allows installing several versions of a library by adding a slot for each library. Therefore, you need to setup the following structures, under your AS 7 distribution:

  • modules/com/sun/jsf-impl/2.2 for the implementation
  • modules/javax/faces/api/2.2 for the API

Now, into the modules/com/sun/jsf-impl/2.2 folder copy the jsf-impl-2.2.0-20130322.075047-259.jar and add the following module.xml

<module xmlns="urn:jboss:module:1.1" name="com.sun.jsf-impl" slot="2.2">
        <property name="jboss.api" value="private"/>

        <module name="javax.faces.api" slot="2.2"/>
        <module name="javaee.api"/>
        <module name="javax.servlet.jstl.api"/>
        <module name="org.apache.xerces" services="import"/>
        <module name="org.apache.xalan" services="import"/>

        <resource-root path="jsf-impl-2.2.0-20130322.075047-259.jar"/>

Much the same way, into the modules/javax/faces/api/2.2 folder copy the file jsf-api-2.2.0-20130322.075010-270.jar and add the following module.xml:

<module xmlns="urn:jboss:module:1.1" name="javax.faces.api" slot="2.2">
        <module name="javax.el.api" export="true"/>
        <module name="javax.servlet.api" export="true"/>
        <module name="javax.servlet.jsp.api" export="true"/>
        <module name="javax.servlet.jstl.api" export="true"/>
        <module name="javax.validation.api" export="true"/>
        <module name="com.sun.jsf-impl" slot="2.2"/>

       <resource-root path="jsf-api-2.2.0-20130322.075010-270.jar"/>

In order to trigger the JSF 2.2 Api we need to deploy an application which actually uses JSF, therefore deploy any web application which contains a JSF 2.2 aware faces-config.xml:



Last thing, if you have installed JSF 2.2 as slot on your AS7 installation, you need to provide in your jboss-deployment-structure.xml file a dependency towards the JSF 2.2 libs and an exclusion for the default JSF 2.1 API:

     <module name="javax.faces.api" />
     <module name="com.sun.jsf-impl" />
     <module name="javax.faces.api" slot="2.2"/>
     <module name="com.sun.jsf-impl" slot="2.2"/>

That’s it! Once deployed your JSF 2.2 applicaion you should check on the console that the new JSF 2.2 Api have been correctly registered:

jsf 2.2 tutorial java ee 7
Although we haven’t code any example as yet with JSF 2.2 Api (but we are going soon to have a taste of it!) if you want to try some of the new JSF 2.2 features either add to your Eclipse library the two JAR files we have downloaded from the Maven repository or, if you are using Maven for your project, add thew following dependency to your pom.xml:


Last note: the above configuration has been tested on the jboss-eap-6.1 platform but it should work just the same on the AS 7.1.1 community version.