sun.com docs.sun.com My Sun Worldwide Sites

  Previous Contents Next

Setting Up Your Application to Use Project Dynamic Faces

Before you can use Project Dynamic Faces with your JavaServer Faces application, you need to do three things:

  • Initialize the FacesServlet instance with the custom Lifecycle object used to process Ajax requests.

  • Add the required JAR files to your application.

  • Set up your pages to use Dynamic Faces.

Initializing the Lifecycle Object

At the heart of Dynamic Faces are the custom Lifecycle and ViewRoot implementations. To make the JavaServer Faces technology runtime aware of the custom Lifecycle object, you must tell the FacesServlet instance about the object using an initialization parameter in your deployment descriptor:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <init-param>
        <param-name>javax.faces.LIFECYCLE_ID</param-name>
        <param-value>com.sun.faces.lifecycle.PARTIAL</param-name>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

The custom ViewRoot is automatically installed in the system by the JavaServer Faces runtime, so you don't need to configure it.

Adding the Required JAR Files to the Application

Project Dynamic Faces depends on the following JAR files to be available in the WEB-INF/lib directory of the web application class loader:

  • jsf-extensions-common.jar

  • jsf-extensions-dynamic-faces.jar

  • jsf-extensions-flash.jar

  • A commons-logging JAR file at version 1.1 or later

  • A shale-remoting JAR file at version 1.0.3 or later

The Sun Web Developer Pack has these JAR files installed in the lib directory of the domain of the web container over which you installed the Sun Web Developer Pack. Therefore, you do not need to put the JAR files into the WEB-INF/lib directory of your web application if you are deploying to a web container over which the Sun Web Developer Pack has been installed. If you deploy to a different web container that does not have the Sun Web Developer Pack installed, then you need to include the JAR files in the WEB-INF/lib directory of the web application.

The set of NetBeans modules for the Sun Web Developer Pack includes a module called webpack-libraries, which allows you to set the path to the JAR files you need from the Sun Web Developer Pack and include them in your archive. See the About chapter for instructions on how obtain this module and point to your installation of the Sun Web Developer Pack.

After you have followed these instructions and have created your NetBeans project, you can include the JAR files in the project by performing the following task.

Adding the JAR Files to Your Project

  1. Right-click the project.
  2. Select Properties.
  3. Expand the Build node.
  4. Select the Packaging node.
  5. Click Add Library.
  6. Select SWDP-jsf-extensions.
  7. Click OK.

Setting Up the Page to Use Dynamic Faces

To use Dynamic Faces in your page, you need to declare the Dynamic Faces tag library in the page, include the necessary scripts in your page. You should also set the prependId of your form tag to false for reasons explained in this section.

Setting Up the Page to Use Dynamic Faces

  1. Add the following tag library definition to the top of your JSP page:
    <%@ taglib prefix="jsfExt" 
        uri="http://java.sun.com/jsf/extensions/dynafaces" %>
  2. Add the following tag inside the head tag of your page:
    <jsfExt:scripts />

    The scripts tag renders the <script> elements for the JavaScript technology files that Dynamic Faces provides. If you are using the ajaxZone tag, you do not need to add the scripts tag. When you include the ajaxZone tag in a page, the necessary scripts are automatically included in the page as well.

  3. Set the prependId attribute to false:
    <f:view>
    ...
    <h:form prependId="false" id="form">
      ...
    </h:form>
    ...
    </f:view>

    By setting the prependId attribute to false, you can refer to component IDs without prepending the form's ID. When you work with Ajax, you need to refer to client IDs quite often. With prependId set to false, you can simply refer directly to the client ID, thereby reducing the size of Ajax transactions and avoiding extra typing.

Previous Contents Next
Company Info Contact Terms of Use Privacy Copyright 1994-2007 Sun Microsystems, Inc.