MyFaces JSF RichFaces

# Settings for different environments

RichFaces comes with support for all tags (components) included in the JavaServer Faces specification. To add RichFaces capabilities to the existing JSF project you should just put the RichFaces libraries into the lib folder of the project and add filter mapping. The behavior of the existing project doesn't change just because of RichFaces.

&wadParams;

## Sun JSF RI

RichFaces works with any implementation of JSF (both JSF 1.1 and JSF 1.2) and with most JSF component libraries without any additional settings. For more information look at:

- java.sun.com

## Apache MyFaces

RichFaces works with all Apache MyFaces versions (1.1.1 - 1.1.6) including specific libraries like TOMAHAWK Sandbox and Trinidad (the previous ADF Faces). However, there are some considerations to take into account for configuring applications to work with MyFaces and RichFaces.

There are some problems with different filters defined in the web.xml file clashing. To avoid these problems, the RichFaces filter must be the first one among other filters in the web.xml configuration file.

For more information look at:http://myfaces.apache.org

There's one more problem while using MyFaces + Seam. If you use this combination you should use <a4j:page> inside <f:view> (right after it in your code) wrapping another content inside your pages because of some problems in realization of <f:view> in myFaces.

The problem is to be overcome in the nearest future.

## Facelets Support

A high-level support for Facelets is one of our main support features. When working with RichFaces, there is no difference what release of Facelets is used.

You should also take into account that some JSF frameworks such as Facelets use their own ViewHandler and need to have it first in the chain of ViewHandlers and the RichFaces AjaxViewHandler is not an exception. At first RichFaces installs its ViewHandler in any case, so in case of two frameworks, for example RichFaces + Facelets, no changes in settings are required. Although, when more then one framework (except RichFaces) is used, it's possible to use the VIEW_HANDLERS parameter defining these frameworks view handlers according to its usage order in it. For example, the declaration:

Example:

        <context-param>
          <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
          <param-value>com.sun.facelets.FaceletViewHandler</param-value>
        </context-param>

says that Facelets will officially be the first, however AjaxViewHandler will be a little ahead temporarily to do some small, but very important job.

Note:

In this case you don't have to define FaceletViewHandler in the WEB-INF/faces-config.xml.

## JBoss Seam Support

RichFaces now works out-of-the-box with JBoss Seam and Facelets running inside JBoss AS 4.0.4 and higher. There is no more shared JAR files needed. You just have to package the RichFaces library with your application.

Your web.xml for Seam 1.2 must be like this:

    <?xml version="1.0" ?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
            version="2.4">

        <!-- richfaces -->

        <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>
            <url-pattern>*.seam</url-pattern>
        </filter-mapping>

        <context-param>
            <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
            <param-value>org.jboss.seam.ui.facelet.SeamFaceletViewHandler</param-value>
        </context-param>

        <!-- Seam -->

        <listener>
            <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
        </listener>

        <servlet>
            <servlet-name>Seam Resource Servlet</servlet-name>
            <servlet-class>org.jboss.seam.servlet.ResourceServlet</servlet-class>
        </servlet>

        <servlet-mapping>
            <servlet-name>Seam Resource Servlet</servlet-name>
            <url-pattern>/seam/resource/*</url-pattern>
        </servlet-mapping>

        <filter>
            <filter-name>Seam Filter</filter-name>
            <filter-class>org.jboss.seam.web.SeamFilter</filter-class>
        </filter>

        <filter-mapping>
            <filter-name>Seam Filter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

       <!-- MyFaces -->

        <listener>
             <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
        </listener>

        <!-- JSF -->

        <context-param>
            <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
            <param-value>client</param-value>
        </context-param>

        <context-param>
            <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
            <param-value>.xhtml</param-value>
        </context-param>

        <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>*.seam</url-pattern>
        </servlet-mapping>

    </web-app>

Seam 2 supports RichFaces Filter. Thus your web.xml for Seam 2 must be like this:

    <?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>org.ajax4jsf.VIEW_HANDLERS</param-name>
            <param-value>com.sun.facelets.FaceletViewHandler</param-value>
        </context-param>

        <!-- Seam -->

        <listener>
            <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
        </listener>

        <servlet>
            <servlet-name>Seam Resource Servlet</servlet-name>
            <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
        </servlet>

        <servlet-mapping>
            <servlet-name>Seam Resource Servlet</servlet-name>
            <url-pattern>/seam/resource/*</url-pattern>
        </servlet-mapping>

        <filter>
            <filter-name>Seam Filter</filter-name>
            <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
        </filter>

        <filter-mapping>
            <filter-name>Seam Filter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

        <!-- JSF -->

        <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>true</param-value>
        </context-param>

        <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>*.seam</url-pattern>
        </servlet-mapping>

    </web-app>

Only one issue still persists while using Seam with MyFaces. Look at myFaces part of this section.

## Portlet Support

JBoss Portlets have support since version Ajax4jsf 1.1.1. This support is improved in Richfaces 3.1.0. Provide your feedback on compatible with RichFaces if you face some problems.

## Sybase EAServer

The load-on-startup for the Faces Servlet had to be set to 0 in web.xml.

Example:

    ...
          <servlet>
              <servlet-name>Faces Servlet</servlet-name>
              <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
              <load-on-startup>0</load-on-startup>
        </servlet>
    ...

This is because, EAServer calls servlet init() before the ServletContextInitializer. Not an EAServer bug, this is in Servlet 2.3 spec.