7 Working with JSF and MyFaces Applications

This chapter describes how to configure Coherence*Web for JavaServer Faces (JSF) and MyFaces applications. JSF is a framework that enables you to build user interfaces for Web applications. MyFaces, from the Apache Software Foundation, provides JSF components that extend the JSF specification. MyFaces components are completely compatible with the JSF 1.1 Reference Implementation or any other compatible implementation.

This chapter contains the following sections:

7.1 Configuring for all JSF and MyFaces Web Applications:

JSF and MyFaces attempts to cache the state of the view in the session object. This state data should be serializable by default, but there could be situations where this would not be the case. For example:

  • If Coherence*Web reports IllegalStateException due to a non-serializable class, and all the attributes placed in the session by your Web-application are serializable, then you must configure JSF/MyFaces to store the state of the view in a hidden field on the rendered page.

  • If the Web application puts non-serializable objects in the session object, you must set the coherence-preserve-attributes context parameter to true.

The JSF parameter javax.faces.STATE_SAVING_METHOD identifies where the state of the view is stored between requests. By default, the state is saved in the servlet session. Set the STATE_SAVING_METHOD parameter to client in the context-param stanza of the web.xml file, so that JSF stores the state of the entire view in a hidden field on the rendered page. If you do not, then JSF may attempt to cache that state, which is not serializable, in the session object.

Example 7-1 illustrates setting the STATE_SAVING_METHOD parameter in the web.xml file.

Example 7-1 Setting STATE_SAVING_METHOD in the web.xml File

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

7.2 Configuring for Instrumented Applications that use MyFaces

If you are deploying the MyFaces application with the Coherence*Web WebInstaller (that is, an instrumented application), then you might have to complete an additional step based on the version of MyFaces.

  • If you are using Coherence*Web WebInstaller to deploy a Web-application built with a pre-1.1.n version of MyFaces, then nothing more needs to be done.

  • If you are using Coherence*Web WebInstaller to deploy a Web-application built with a 1.2.x version of MyFaces, then add the context parameter org.apache.myfaces.DELEGATE_FACES_SERVLET to the web.xml file. This parameter allows you to specify a custom servlet instead of the default javax.faces.webapp.FacesServlet.

    Example 7-2 illustrates setting the DELEGATE_FACES_SERVLET context parameter in the web.xml file.

Example 7-2 Setting DELEGATE_FACES_SERVLET in the web.xml File

...
<context-param>
    <param-name>org.apache.myfaces.DELEGATE_FACES_SERVLET</param-name>
    <param-value>com.tangosol.coherence.servlet.api23.ServletWrapper</param-value>
</context-param>
...

7.3 Configuring for Instrumented Applications that use Mojarra

If you are using Coherence*Web WebInstaller to deploy a Web application based on the JSF Reference Implementation (Mojarra), then you must declare the FacesServlet class in the servlet stanza of the web.xml file.

Example 7-3 Declaring the Faces Servlet in the web.xml File

...
<servlet>
     <servlet-name>Faces Servlet (for loading config)</servlet-name>
     <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
 </servlet>
...