A script-enabled browser is required for this page to function properly.

Getting Started with ADF Faces

This chapter describes the process of setting up your user interface project to use ADF Faces. It also supplies basic information about creating and laying out a web page that will rely on ADF Faces components for the user interface.

The chapter includes the following sections:

Introduction to ADF Faces

Oracle ADF Faces is a 100% JavaServer Faces (JSF) compliant component library that offers a broad set of enhanced UI components for JSF application development. Based on the JSF JSR 127 specification, ADF Faces components can be used in any IDE that supports JSF. More specifically, ADF Faces works with Sun's JSF Reference Implementation 1.1_01 (or later) and Apache MyFaces 1.0.8 (or later).

ADF Faces ensures a consistent look and feel for your application, allowing you to focus more on user interface interaction than look and feel compliance. The component library supports multi–language and translation implementations, and accessibility features. ADF Faces also supports multiple render kits for HTML, mobile, and telnet users—this means you can build web pages with the same components, regardless of the device that will be used to display the pages.

Using the partial-page rendering features of ADF Faces components, you can build interactive web pages that update the display without requiring a complete page refresh. In the future, Oracle plans to provide render kits that make even more sophisticated use of AJAX technologies—JavaScript, XML, and the Document Object Model (DOM)—to deliver more Rich Internet Applications with interactivity nearing that of desktop-style applications.

ADF Faces has many of the framework and component features most needed by JSF developers today, including:

ADF Faces UI components include advanced tables with column sorting and row selection capability, tree components for displaying data hierarchically, color and date pickers, and a host of other components such as menus, command buttons, shuttle choosers, and progress meters.

ADF Faces out-of-the-box components simplify user interaction, such as the input file component for uploading files, and the select input components with built-in dialog support for navigating to secondary windows and returning to the originating page with the selected values.

For more information about ADF Faces, refer to the following resources:

When you create JSF JSP pages that use ADF Faces components for the UI and use JSF technology for page navigation, you can leverage the advantages of the Oracle Application Development Framework (Oracle ADF) by using the ADF Model binding capabilities for the components in the pages. For information about data controls and the ADF Model, see Declarative Development with Oracle ADF and JavaServer Faces.

Table: Supported Platforms for ADF Faces shows the platforms currently supported for ADF Faces.

Supported Platforms for ADF Faces

User Agent Windows Solaris Mac OS X Red Hat Linux Windows Mobile Palm OS

Internet Explorer

6.0 *




2003+


Mozilla

1.7.x



1.7.x



Firefox

1.0.x



1.0.x



Safari



1.3, 2.0 **




WebPro (Mobile)






3.0


* Accessibility and BiDi is only supported on IE on Windows.

** Apple bug fixes provided in Safari 1.3 patch 312.2 and Safari 2.0 patch 412.5 required.


Tip:

On a UNIX server box, button images may not render as expected. Assuming you're using JDK 1.4 or later, Oracle strongly recommends using -Djava.awt.headless=true as a command-line option with UNIX boxes.

Read this chapter to understand:

Setting Up a Workspace and Project

JDeveloper provides application templates that enable you to quickly create the workspace and project structure with the appropriate combination of technologies already specified. The SRDemo application uses the Web Application [JSF, EJB, TopLink] application template, which creates one project for the data model, and one project for the controller and view (user interface) components in a workspace.

To create a new application workspace in JDeveloper and choose an application template:

  1. Right-click the Applications node in the Application Navigator and choose New Application.

  2. In the Create Application dialog, select the Web Application [JSF, EJB, TopLink] application template from the list.

You don't have to use JDeveloper application templates to create an application workspace—they are provided merely for your convenience.

At times you might already have an existing WAR file and you want to import it into JDeveloper.

To import a WAR file into a new project in JDeveloper:

  1. Right-click your application workspace in the Application Navigator and choose New Project.

  2. In the New Gallery, expand General in the Categories tree, and select Projects.

  3. In the Items list, double-click Project from WAR File.

  4. Follow the wizard instructions to complete creating the project.

What Happens When You Use an Application Template to Create a Workspace

By default, JDeveloper names the project for the data model Model, and the project for the user interface and controller ViewController. You can rename the projects using File > Rename after you've created them, or you can use Tools > Manage Templates to change the default names that JDeveloper uses.


Note:

The illustrations and project names used in this chapter are the JDeveloper default names. The SRDemo application, however, uses the project name UserInterface for the JSF view and controller components, and DataModel for the project that contains the EJB session beans and TopLink using plain old Java objects. The SRDemo application also has additional projects in the Application Navigator (for example, BuildAndDeploy), which you create manually to organize your application components into logical folders.

Figure: ViewController Project in the Navigator After You Create a Workspace shows the Application Navigator view of the ViewController project after you create the workspace.

ViewController Project in the Navigator After You Create a Workspace

New ViewController workspace in Application Navigator

Figure: ViewController Folders in the File System After You Create a Workspace shows the actual folders JDeveloper creates in the <JDEV_HOME>/jdev/mywork folder in the file system.

ViewController Folders in the File System After You Create a Workspace

New ViewController folders in file system

For example, if you created a workspace named Application1, the ViewController folder and its subfolders would be located in <JDEV_HOME>/jdev/mywork/Application1 in the file system.

When you use the Web Application [JSF, EJB, TopLink] template to create a workspace, JDeveloper does the following for you:

Starter web.xml File

Part of a JSF application's configuration is also determined by the contents of its J2EE application deployment descriptor, web.xml. The web.xml file defines everything about your application that a server needs to know (except the root context path, which is assigned by JDeveloper or the system administrator when the application is deployed). Typical runtime settings include initialization parameters, custom tag library location, and security settings.

Example: Starter web.xml File Created by JDeveloper shows the starter web.xml file JDeveloper first creates for you.

Starter web.xml File Created by JDeveloper

<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app 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" xmlns="http://java.sun.com/xml/ns/j2ee">
  <description>Empty web.xml file for Web Application</description>

  <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>/faces/*</url-pattern>
  </servlet-mapping>
...
</web-app>

The JSF servlet and servlet mapping configuration settings are automatically added to the starter web.xml file when you first create a JSF project.

  • JSF servlet: The JSF servlet is javax.faces.webapp.FacesServlet, which manages the request processing lifecycle for web applications utilizing JSF to construct the user interface. The configuration setting maps the JSF servlet to a symbolic name.

  • JSF servlet mapping: The servlet mapping maps the URL pattern to the JSF servlet's symbolic name. You can use either a path prefix or an extension suffix pattern.

    By default, JDeveloper uses the path prefix /faces/*. This means that when the URL http://localhost:8080/SRDemo/faces/index.jsp is issued, the URL activates the JSF servlet, which strips off the faces prefix and loads the file /SRDemo/index.jsp.

To edit web.xml in JDeveloper, right-click web.xml in the Application Navigator and choose Properties from the context menu to open the Web Application Deployment Descriptor editor. If you're familiar with the configuration element names, you can also use the XML editor to modify web.xml.

For reference information about the configuration elements you can use in web.xml when you work with JSF, see web.xml.


Note:

If you use ADF data controls to build databound web pages, JDeveloper adds the ADF binding filter and a servlet context parameter for the application binding container in web.xml. For more information, see Configuring the ADF Binding Filter.

Starter faces-config.xml File

The JSF configuration file is where you register a JSF application's resources such as custom validators and managed beans, and define all the page-to-page navigation rules. While an application can have any JSF configuration filename, typically the filename is faces-config.xml. Example: Starter faces-config.xml File Created by JDeveloper shows the starter faces-config.xml file JDeveloper first creates for you when you create a project that uses JSF technology.

Small applications usually have one faces-config.xml file. For information about using multiple configuration files, see What You May Need to Know About Multiple JSF Configuration Files.

Starter faces-config.xml File Created by JDeveloper

<?xml version="1.0" encoding="windows-1252"?>
<!DOCTYPE faces-config PUBLIC
  "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
  "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config xmlns="http://java.sun.com/JSF/Configuration">

</faces-config>

In JDeveloper you can use either editor to edit faces-config.xml:

  • JSF Configuration Editor: Oracle recommends you use the JSF Configuration Editor because it provides visual editing.

  • XML Source Editor: Use the source editor to edit the file directly, if you're familiar with the JSF configuration elements.

To launch the JSF Configuration Editor:

  1. In the Application Navigator, double-click faces-config.xml to open the file.

    By default JDeveloper opens faces-config.xml in Diagram mode, as indicated by the active Diagram tab at the bottom of the editor window. When creating or modifying JSF navigation rules, Oracle suggests you use the Diagram mode of the JSF Configuration Editor.

    In JDeveloper a diagram file, which lets you create and manage page flows visually, is associated with faces-config.xml. For information about creating JSF navigation rules, see Adding Page Navigation.

  2. To create or modify configuration elements other than navigation rules, use the Overview mode of the JSF Configuration Editor. At the bottom of the editor window, select Overview.

Both Overview and Diagram modes update the faces-config.xml file.


Tip:

JSF allows more than one <application> element in a single faces-config.xml file. The JSF Configuration Editor only allows you to edit the first <application> instance in the file. For any other <application> elements, you'll need to edit the file directly using the XML editor.

For reference information about the configuration elements you can use in faces-config.xml, see faces-config.xml.


Note:

If you use ADF data controls to build databound web pages, JDeveloper adds the ADF phase listener in faces-config.xml, as described in What Happens When You Use the Data Control Palette.

What You May Need to Know About the ViewController Project

The ViewController project contains the web content that includes the web pages and other resources of the web application. By default, the JDeveloper web application template you select adds the word "controller" to the project name to indicate that the web application will include certain files that define the application's flow or page navigation (controller), in addition to the web pages themselves (view).


Note:

The concept of separating page navigation from page display is often referred to as Model 2 to distinguish from earlier style (Model 1) applications that managed page navigation entirely within the pages themselves. In a Model 2 style application, the technology introduces a specialized servlet known as a page controller to handle page navigation events at runtime.

The technology that you use to create web pages in JDeveloper will determine the components of the ViewController project and the type of page controller your application will use. The SRDemo application uses JSF combined with JSP to build the web pages:

JDeveloper tools will help you to easily bind the JSF components with the Java objects of the Model project, thus creating databound UI components. As described earlier, the ViewController project contains the web pages for the user interface. To declaratively bind UI components in web pages to a data model, the ViewController project must be able to access data controls in the Model project. To enable the ViewController project to access the data controls, a dependency on the Model project must be specified. The first time you drag an item from the Data Control Palette and drop it onto a JSF page, JDeveloper configures the dependency for you. If you wish to set the dependency on the Model project manually, use the following procedure.

To set dependency on a Model project for a ViewController project in JDeveloper:

  1. Double-click ViewController in the Application Navigator to open the Project Properties dialog.

  2. Select Dependencies and then select the checkbox next to Model.jpr.

What You May Need to Know About Multiple JSF Configuration Files

A JSF application can have more than one JSF configuration file. For example, if you need individual JSF configuration files for separate areas of your application, or if you choose to package libraries containing custom components or renderers, you can create a separate JSF configuration file for each area or library.

To create another JSF configuration file, simply use a text editor or use the JSF Page Flow & Configuration wizard provided by JDeveloper.

To launch the JSF Page Flow & Configuration wizard:

  1. In the Application Navigator, right-click ViewController and choose New.

  2. In the New Gallery window, expand Web Tier. Select JSF and then double-click JSF Page Flow & Configuration (faces-config.xml).

When creating a JSF configuration file for custom components or other JSF classes delivered in a library JAR:

This is helpful for applications that have packaged libraries containing custom components and renderers.

When creating a JSF configuration file for a separate application area:

This is helpful for large-scale applications that require separate configuration files for different areas of the application.

Configuring for Multiple JSF Configuration Files in the web.xml File

<context-param>
  <param-name>javax.faces.CONFIG_FILES</param-name>
  <param-value>/WEB-INF/faces-config1.xml,/WEB-INF/faces-config2.xml</param-value>
</context-param>

Any JSF configuration file, whether it is named faces-config.xml or not, must conform to Sun's DTD located at http://java.sun.com/dtd/web-facesconfig_1_x.dtd. If you use the wizard to create a JSF configuration file, JDeveloper takes care of this for you.

If an application uses several JSF configuration files, at runtime JSF finds and loads the application's configuration settings in the following order:

  1. Searches for files named META-INF/faces-config.xml in any JAR files for the application, and loads each as a configuration resource (in reverse order of the order in which they are found).

  2. Searches for the javax.faces.CONFIG_FILES context parameter set in the application's web.xml file. JSF then loads each named file as a configuration resource.

  3. Searches for a file named faces-config.xml in the WEB-INF directory and loads it as a configuration resource.

JSF then instantiates an Application class and populates it with the settings found in the various configuration files.

Creating a Web Page

While JSF supports a number of presentation layer technologies, JDeveloper uses JSP as the presentation technology for creating JSF web pages. When you use JSF with JSP, the JSF pages can be JSP pages (.jsp) or JSP documents (.jspx). JSP documents are well-formed XML documents, and the XML standard offers many benefits such as validation against a document type definition. Hence, Oracle recommends that you use JSP documents when you build your web pages using ADF Faces components. Unless otherwise noted, the term JSF page in this guide refers to both JSF JSP pages and JSF JSP documents.

JDeveloper gives you two ways to create JSF pages that will appear in your ViewController project:

How to Add a JSF Page uses the latter technique. It also introduces the JSF Navigation Modeler, which allows you to plan out your application pages in the form of a diagram, to define the navigation flow between the pages, and to create the pages.

How to Add a JSF Page

Oracle recommends using the JSF navigation diagram to plan out and build your application page flow. Because the JSF navigation diagram visually represents the pages of the application, it is also an especially useful way to drill down into individual web pages when you want to edit them in the JSP/HTML Visual Editor.

To add a JSF page to your ViewController project using the JSF navigation diagram:

  1. Expand the ViewController - Web Content - WEB-INF folder in the Application Navigator and double-click faces-config.xml or choose Open JSF Navigation from the ViewController context menu to open the faces-config.xml file.

    By default, JDeveloper opens the file in the Diagram tab, which is the JSF navigation diagram. If you've just started the ViewController project, the navigation diagram would be an empty drawing surface. If you don't see a blank drawing surface when you open faces-config.xml, select Diagram at the bottom of the editor.

  2. In the Component Palette, select JSF Navigation Diagram from the dropdown list, and then select JSF Page.

    Page representation icon with yellow warning label overlaid
  3. Click on the diagram in the place where you want the page to appear. A page icon with a label for the page name appears on the diagram. The page icon has a yellow warning overlaid–this means you haven't created the actual page yet, just a representation of the page.

  4. To create the new page, double-click the page icon and use the Create JSF JSP wizard.

    When creating a page in JDeveloper for the first time, be sure to complete all the steps of the wizard.

  5. In Step 1 of the Create JSF JSP wizard, select JSP Document (*.jspx) for the JSP file Type.

  6. Enter a filename and accept the default directory name or choose a new location. By default, JDeveloper saves files in /ViewController/public_html in the file system.

  7. In Step 2 of the wizard, keep the default selection for not using component binding automatically.

  8. In Step 3 of the wizard, make sure that these libraries are added to the Selected Libraries list:

    • ADF Faces Components

    • ADF Faces HTML

    • JSF Core

    • JSF HTML

  9. Accept the default selection for the remaining page and click Finish.

Your new JSF page will open in the JSP/HTML Visual Editor where you can begin to lay out the page using ADF Faces components from the Component Palette or databound components dropped from the Data Control Palette.

If you switch back to the JSF navigation diagram (by clicking the faces-config.xml editor tab at the top), you will notice that the page icon no longer has the yellow warning overlaid.


Tip:

If you create new JSF pages using the wizard from the New Gallery, you can drag them from the Application Navigator to the JSF navigation diagram when designing the application page flow.

What Happens When You Create a JSF Page

Figure: ViewController Project in the Navigator After You Add a JSF Page shows the Application Navigator view of the ViewController project after you complete the wizard steps to add a JSF page.

ViewController Project in the Navigator After You Add a JSF Page

New JSF page in ViewController project in navigator

Figure: ViewController Folders in the File System After You Add a JSF Page shows the actual folders JDeveloper creates in the <JDEV_HOME>/jdev/mywork folder in the file system.

ViewController Folders in the File System After You Add a JSF Page

ViewController folders in file system

JDeveloper does the following when you create your first JSF page in a ViewController project via the JSF navigation diagram:

Whether you create JSF pages by launching the Create JSF JSP wizard from the JSF navigation diagram or the New Gallery, by default JDeveloper creates starter pages that are JSF JSP 2.0 files, and automatically imports the JSF tag libraries into the starter pages. If you select to add the ADF Faces tag libraries in step 3 of the wizard, JDeveloper also imports the ADF Faces tag libraries into the starter pages. Example: Starter JSF JSP Document Created by JDeveloper shows a starter page for a JSF JSP document.

Starter JSF JSP Document Created by JDeveloper

<?xml version='1.0' encoding='windows-1252'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces"
          xmlns:afh="http://xmlns.oracle.com/adf/faces/html"
  <jsp:output omit-xml-declaration="true" doctype-root-element="HTML"
              doctype-system="http://www.w3.org/TR/html4/loose.dtd"
              doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
  <jsp:directive.page contentType="text/html;charset=windows-1252"/>
  <f:view>
    <html>
      <head>
        <meta http-equiv="Content-Type" 
              content="text/html; charset=windows-1252"/>
        <title>untitled1</title>
      </head>
      <body>
        <h:form></h:form>
      </body>
    </html>
  </f:view>
</jsp:root>

What You May Need to Know About Using the JSF Navigation Diagram

In the JSF navigation diagram, you will notice that the label of the page icon has an initial slash (/), followed by the name of the page. The initial slash is required so that the page can be run from the diagram. If you remove the slash, JDeveloper will automatically reinstate it for you.

Be careful when renaming and deleting pages from the JSF navigation diagram:

For information about the JSF navigation diagram and creating navigation rules, see Adding Page Navigation.

What You May Need to Know About ADF Faces Dependencies and Libraries

ADF Faces is compatible with JDK 1.4 (and higher), and cannot run on a server that supports only Sun's JSF Reference Implementation 1.0. The implementation must be JSF 1.1_01 (or later) or Apache MyFaces 1.0.8 (or later).

The ADF Faces deliverables are:

ADF Faces provides two tag libraries that you can use in your JSF pages:

Table: ADF Faces and JSF Tag Libraries shows the URIs and default prefixes for the ADF Faces and JSF tag libraries used in JDeveloper.

ADF Faces and JSF Tag Libraries

Library URI Prefix

ADF Faces Core

http://xmlns.oracle.com/adf/faces

af

ADF Faces HTML

http://xmlns.oracle.com/adf/faces/html

afh

JSF Core

http://java.sun.com/jsf/core

f

JSF HTML

http://java.sun.com/jsf/html

h


JDeveloper also provides the ADF Faces Cache and ADF Faces Industrial tag libraries, which use the prefix afc and afi, respectively. For information about ADF Faces Cache, see Optimizing Application Performance with Caching. For information about ADF Faces Industrial, see the JDeveloper online help topic "Developing ADF Mobile Applications".

All JSF applications must be compliant with the Servlet specification, version 2.3 (or later) and the JSP specification, version 1.2 (or later). The J2EE web container that you deploy to must provide the necessary JAR files for the JavaServer Pages Standard Tag Library (JSTL), namely jstl.jar and standard.jar. The JSTL version to use depends on the J2EE web container:

For complete information about ADF Faces and JSF deployment requirements, see Deploying ADF Applications.

Laying Out a Web Page

Most of the SRDemo pages use the ADF Faces panelPage component to lay out the entire page. The panelPage component lets you define specific areas on the page for branding images, navigation menus and buttons, and page-level or application-level text, ensuring that all web pages in the application will have a consistent look and feel. Figure: Page Layout Created with a PanelPage Component shows an example of a page created by using a panelPage component.

Page Layout Created with a PanelPage Component

Page layout showing menu tabs and bar, and global buttons

After you create a new JSF page using the wizard, JDeveloper automatically opens the blank page in the JSP/HTML Visual Editor. To edit a page, you can use any combination of JDeveloper's page design tools you're comfortable with, namely:

When you make changes to a page in one of the design tools, the other tools are automatically updated with the changes you made.

How to Add UI Components to a JSF Page

You can use both standard JSF components and ADF Faces components within the same JSF page. For example, to insert and use the panelPage component in a starter JSF page created by JDeveloper, you could use the following procedure.

To insert UI components into a JSF page:

  1. If not already open, double-click the starter JSF page in the Application Navigator to open it in the visual editor.

  2. In the Component Palette, select ADF Faces Core from the dropdown list.

  3. Drag and drop PanelPage from the palette to the page in the visual editor.

    h:form surrounded with box outline

    As you drag a component on the page in the visual editor, notice that the Structure window highlights the h:form component with a box outline, indicating that the h:form component is the target component. The target component is the component into which the source component will be inserted when it is dropped.

  4. In the Structure window, right-click the newly inserted af:panelPage or any of the PanelPage facets, and choose from the Insert before, Insert inside, or Insert after menu to add the UI components you desire.

    af:panelPage and PanelPage facet folders in Structure window

    You create your input or search forms, tables, and other page body contents inside the panelPage component. For more information about panelPage and its facets, see Using the PanelPage Component.


    Tip:

    Using the context menu in the Structure window to add components ensures that you are inserting components into the correct target locations. You can also drag components from the Component Palette to the Structure window. As you drag a component on the Structure window, JDeveloper highlights the target location with a box outline or a line with an embedded arrow to indicate that the source component will be inserted in that target location when it is dropped. See Editing in the Structure Window for additional information about inserting components using the Structure window.

  5. To edit the attributes for an inserted component, double-click the component in the Structure window to open a property editor, or select the component and then use the Property Inspector.

As you build your page layout by inserting components, you can also use the Data Control Palette to insert databound UI components. Simply drag the item from the Data Control Palette and drop it into the desired location on the page. For further information about using the Data Control Palette, see Displaying Data on a Page.

What Happens When You First Insert an ADF Faces Component

Figure: ViewController Project in the Navigator After You Insert the First ADF Faces Component shows the Application Navigator view of the ViewController project after adding your first ADF Faces component in a page.

ViewController Project in the Navigator After You Insert the First ADF Faces Component

Expanded WEB-INF folder in Application Navigator

When you first add an ADF Faces component to a JSF page, JDeveloper automatically does the following:


Tip:

The WEB-INF/lib and WEB-INF/temp/adf folders are used by JDeveloper at runtime only. To reduce clutter in the Application Navigator, you may exclude them from the ViewController project. Double-click ViewController to open the Project Properties dialog. Under Project Content, select Web Application and then use the Excluded tab to add the folders you wish to exclude.

JSF JSP Document After You Add the First ADF Faces Component

<?xml version='1.0' encoding='windows-1252'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:afh="http://xmlns.oracle.com/adf/faces/html" 
          xmlns:af="http://xmlns.oracle.com/adf/faces">
  <jsp:output omit-xml-declaration="true" doctype-root-element="HTML"
              doctype-system="http://www.w3.org/TR/html4/loose.dtd"
              doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
  <jsp:directive.page contentType="text/html;charset=windows-1252"/>
  <f:view>
    <afh:html>
      <afh:head title="untitled1">
        <meta http-equiv="Content-Type"
              content="text/html; charset=windows-1252"/>
      </afh:head>
      <afh:body>
        <h:form>
          <af:panelPage title="Title 1">
            <f:facet name="menu1"/>
            <f:facet name="menuGlobal"/>
            <f:facet name="branding"/>
            <f:facet name="brandingApp"/>
            <f:facet name="appCopyright"/>
            <f:facet name="appPrivacy"/>
            <f:facet name="appAbout"/>
          </af:panelPage>
        </h:form>
      </afh:body>
    </afh:html>
  </f:view>
</jsp:root>

More About the web.xml File

When you insert an ADF Faces component into a JSF page for the first time, JDeveloper automatically inserts the following ADF Faces configuration settings into web.xml:

  • ADF Faces filter: Installs oracle.adf.view.faces.webapp.AdfFacesFilter, which is a servlet filter to ensure that ADF Faces is properly initialized by establishing a AdfFacesContext object. AdfFacesFilter is also required for processing file uploads. The configuration setting maps AdfFacesFilter to a symbolic name.

  • ADF Faces filter mapping: Maps the JSF servlet's symbolic name to the ADF Faces filter.

  • ADF Faces resource servlet: Installs oracle.adf.view.faces.webapp.ResourceServlet, which serves up web application resources (such as images, style sheets, and JavaScript libraries) by delegating to a ResourceLoader. The configuration setting maps ResourceServlet to a symbolic name.

  • ADF Faces resource mapping: Maps the URL pattern to the ADF Faces resource servlet's symbolic name.

Example: Configuring for ADF Faces in the web.xml File shows the web.xml file after you add the first ADF Faces component.

Configuring for ADF Faces in the web.xml File

<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app 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" xmlns="http://java.sun.com/xml/ns/j2ee">
  <description>Empty web.xml file for Web Application</description>

  <!-- Installs the ADF Faces filter -- >
  <filter>
    <filter-name>adfFaces</filter-name>
    <filter-class>oracle.adf.view.faces.webapp.AdfFacesFilter</filter-class>
  </filter>

  <!-- Adds the mapping to ADF Faces filter -- >
  <filter-mapping>
    <filter-name>adfFaces</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
  </filter-mapping>

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

  <!-- Installs the ADF Faces ResourceServlet -- >
  <servlet>
    <servlet-name>resources</servlet-name>
    <servlet-class>oracle.adf.view.faces.webapp.ResourceServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>

  <!-- Maps URL pattern to the ResourceServlet's symbolic name -->
  <servlet-mapping>
    <servlet-name>resources</servlet-name>
    <url-pattern>/adf/*</url-pattern>
  </servlet-mapping>
...
</web-app>

For reference information about the configuration elements you can use in web.xml when you work ADF Faces, see Tasks Supported by the web.xml File.


Tip:

If you use multiple filters in your application, make sure that they are listed in web.xml in the order in which you want to run them. At runtime, the filters are called in the sequence listed in that file.

More About the faces-config.xml File

As mentioned earlier, JDeveloper creates one empty faces-config.xml file for you when you create a new project that uses JSF technology. When you insert an ADF Faces component into a JSF page for the first time, JDeveloper automatically inserts the default render kit for ADF components into faces-config.xml, as shown in Example: Configuring for ADF Faces Components in the faces-config.xml File.

Configuring for ADF Faces Components in the faces-config.xml File

<?xml version="1.0" encoding="windows-1252"?>
<!DOCTYPE faces-config PUBLIC
  "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
  "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config xmlns="http://java.sun.com/JSF/Configuration">
  ...
  <!-- Default render kit for ADF components -->
  <application>
    <default-render-kit-id>oracle.adf.core</default-render-kit-id>
  </application>
  ...
</faces-config>

Starter adf-faces-config.xml File

When you create a JSF application using ADF Faces components, you configure ADF Faces–specific features (such as skin family and level of page accessibility support) in the adf-faces-config.xml file. The adf-faces-config.xml file has a simple XML structure that enables you to define element properties using the JSF expression language (EL) or static values.

In JDeveloper, when you insert an ADF Faces component into a JSF page for the first time, a starter adf-faces-config.xml file is automatically created for you in the /WEB-INF directory of your ViewController project. Example: Starter adf-faces-config.xml File Created by JDeveloper shows the starter adf-faces-config.xml file.

Starter adf-faces-config.xml File Created by JDeveloper

<?xml version="1.0" encoding="windows-1252"?>
<adf-faces-config xmlns="http://xmlns.oracle.com/adf/view/faces/config">

  <skin-family>oracle</skin-family>

</adf-faces-config>

By default JDeveloper uses the Oracle skin family for a JSF application. You can change this to minimal or use a custom skin. The SRDemo application uses the srdemo skin. If you wish to use a custom skin, you need to create the adf-faces-skins.xml configuration file, and modify adf-faces-config.xml to use the custom skin. For more information, see How to Use Skins.

To edit the adf-faces-config.xml file in JDeveloper, use the following procedure.

To edit the adf-faces-config.xml file:

  1. In the Application Navigator, double-click adf-faces-config.xml to open the file in the XML editor.

  2. If you're familiar with the element names, enter them in the editor. Otherwise use the Structure window to help you insert them.

  3. To use the Structure window, follow these steps:

    1. Right-click any element to choose from the Insert before or Insert after menu, and click the element you wish to insert.

    2. Double-click the newly inserted element in the Structure window to open it in the properties editor.

    3. Enter a value or select one from a dropdown list (if available).

      In most cases you can enter either a JSF EL expression (such as #{view.locale.language=='en' ? 'minimal' : 'oracle'}) or a static value (e.g., <debug-output>true</debug-output>). EL expressions are dynamically reevaluated on each request, and must return an appropriate object (for example, a Boolean object).


Note:

All elements can appear in any order within the root element <adf-faces-config>. You can include multiple instances of any element. For reference information about the configuration elements you can use in adf-faces-config.xml, see adf-faces-config.xml.

Typically, you would want to configure the following in adf-faces-config.xml:

You can also register a custom file upload processor for uploading files. For information, see Configuring a Custom Uploaded File Processor.

Once you have configured elements in the adf-faces-config.xml file, you can retrieve the property values programmatically or by using JSF EL expressions. For more information, see Retrieving Configuration Property Values From adf-faces-config.xml.

What You May Need to Know About Creating JSF Pages

Consider the following when you're developing JSF web pages:

For more tips on using ADF Faces components, see Best Practices for ADF Faces.

Editing in the Structure Window

In the Structure window while inserting, copying, or moving elements, you select an insertion point on the structure that is shown for the page, in relation to a target element. JDeveloper provides visual cues to indicate the location of the insertion point before, after, or contained inside a target element.

When dragging an element to an insertion point, do one of the following:

Horizontal line with upward pointing arrow in center
  • To insert an element before a target element, drag it towards the top of the element until you see a horizontal line with an embedded up arrow, and then release the mouse button.

Horizontal line with downward pointing arrow in center
  • To insert an element after a target element, drag it towards the bottom of the element until you see a horizontal line with an embedded down arrow, and then release the mouse button.

  • To insert or contain an element inside a target element, drag it over the element until it is surrounded by a box outline, and then release the mouse button. If the element is not available to contain the inserted element, the element will be inserted after the target element.

af:panelPage surrounded with box outline

Tip:

A disallowed insertion point is indicated when the drag cursor changes to a circle with a slash.

Displaying Errors

Most of the SRDemo pages use the af:messages tag to display error messages. When you create databound pages using the Data Control Palette, ADF Faces automatically inserts the af:messages tag for you at the top of the page. When there are errors at runtime, ADF Faces automatically displays the messages in a message box offset by color. For more information about error messages, see Displaying Error Messages.

In addition to reporting errors in a message box, you could use a general JSF error handling page for displaying fatal errors such as stack traces in a formatted manner. If you use a general error handling page, use the <error-page> element in web.xml to specify a type of exception for the error page (as shown in Example: Configuring Error-Page and Exception-Type in the web.xml File), or specify the error page using the JSP page directive (as shown in Example: Specifying ErrorPage in a JSF Page Using JSP Directive).

Configuring Error-Page and Exception-Type in the web.xml File

<error-page>
  <exception-type>java.lang.Exception</exception-type>
  <location>/faces/infrastructure/SRError.jspx</location>
</error-page>

Specifying ErrorPage in a JSF Page Using JSP Directive

<jsp:root ...>
  <jsp:output ...>
  <jsp:directive.page contentType="text/html;charset=windows-1252"
                      errorPage="faces/SRError.jspx"/>
  <f:view></f:view>
</jsp:root>

Consider the following if you intend to create and use a general JSF JSP error page:

  • Due to a current limitation in Sun's JSF reference implementation, if you use the Create JSF JSP wizard in JDeveloper to create a JSF JSP error page, you need to replace <f:view></f:view> with <f:subview></f:subview>.

  • In web.xml you need to add the following settings to ADF Faces filter mapping:

    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
    
    
  • In the JSF page that uses the error page, <jsp:directive errorPage=""/> needs to include the faces/ prefix in the errorpage URI, as shown in this code snippet:

    <jsp:directive.page contentType="text/html;charset=windows-1252" 
                        errorPage="faces/SRError.jspx"/>
    

Using the PanelPage Component

The SRDemo pages use panelPage as the main ADF Faces layout component, which lets you lay out an entire page with specific areas for navigation menus, branding images, and page body contents, as illustrated in Figure: Page Layout Created with a PanelPage Component.

The panelPage component uses facets (or JSF f:facet tags) to render children components in specific, predefined locations on the page. Consider a facet as a placeholder for one child component. Each facet has a name and a purpose, which determines where the child component is to be rendered relative to the parent component. The child component is often a container component for other child components.

The panelPage component uses menu1, menu2, and menu3 facets for creating hierarchical, navigation menus that enable users to go quickly to related pages in the application. In the menu facets you could either:

In addition to laying out hierarchical menus, the panelPage component supports other facets for laying out page-level and application-level text, images, and action buttons in specific areas, as illustrated in Figure: Basic Page Layout with Branding Images, Navigation Menus, and Application-Level Text and Figure: Basic Page Layout with Page-Level Actions and Informational Text.

For instructions on how to insert child components into facets or into panelPage itself, see How to Add UI Components to a JSF Page.

PanelPage Facets

Figure: Basic Page Layout with Branding Images, Navigation Menus, and Application-Level Text shows panelPage facets (numbered 1 to 12) for laying out branding images, global buttons, menu tabs, bars, and lists, and application-level text.

Basic Page Layout with Branding Images, Navigation Menus, and Application-Level Text

Page layout. See Table 4-3 for descriptions.

Table: PanelPage Facets for Branding Images, Navigation Menus, and Application-Level Text shows the panelPage facets (as numbered in Figure: Basic Page Layout with Branding Images, Navigation Menus, and Application-Level Text), and the preferred children components that you could use in them. In JDeveloper, when you right-click a facet in the Structure window, the Insert inside context menu shows the preferred component to use, if any.

PanelPage Facets for Branding Images, Navigation Menus, and Application-Level Text

No. Facet Description

1

branding

For a corporate logo or organization branding using objectImage. Renders its child component at the top left corner of the page.

2

brandingApp

For an application logo or product branding using objectImage. Renders its child component after a branding image, if used. If chromeType on panelPage is set to "expanded", the brandingApp image is placed below the branding image.

3

brandingAppContextual

Typically use with outputFormatted text to show the application's current branding context. Set the styleUsage attribute on outputFormatted to inContextBranding.

4

menuSwitch

For a menuChoice component that allows the user to switch to another application from any active page. Renders its child component at the top right corner of the page. The menuChoice component can be bound to a menu model object.

5

menuGlobal

For a menuButtons component that lays out a series of menu items as global buttons. Global buttons are buttons that are always available from any active page in the application (for example a Help button). Renders its children components at the top right corner of the page, before a menuSwitch child if used. A text link version of a global button is automatically repeated at the bottom of the page. The menuButtons component can be bound to a menu model object.

6

menu1

For a menuTabs component that lays out a series of menu items as tabs. Renders its children components (right justified) at the top of the page, beneath any branding images, menu buttons, or menu switch. A text link version of a tab is automatically repeated at the bottom of the page. Menu tab text links are rendered before the text link versions of global buttons. Both types of text links are centered in the page. The menuTabs component can be bound to a menu model object.

7

menu2

For a menuBar component that lays out a series of menu items in a horizontal bar, beneath the menu tabs. The children components are left justified in the bar, and separated by vertical lines. The menuBar component can be bound to a menu model object.

8

menu3

For a menuList component that lays out a bulleted list of menu items. Renders the children components in an area offset by color on the left side of a page, beneath a menu bar. The menuList component can be bound to a menu model object.

9

search

For a search area using an inputText component. Renders its child component beneath the horizontal menu bar. A dotted line separates it from the page title below.

10

appAbout

For a link to more information about the application using commandLink. The link text appears at the bottom left corner of the page.

11

appCopyright

For copyright text using outputText. The text appears above the appAbout link.

12

appPrivacy

For a link to a privacy policy statement for the application using commandLink. The link text appears at the bottom right corner of the page.



Tip:

Many UI components support facets, not only panelPage. To quickly add or remove facets on a component, right-click the component in the Structure window and choose Facets - <component name>, where <component name> is the name of the UI component. If the component supports facets, you'll see a list of facet names. A checkmark next to a name means the f:facet element for that facet is already inserted in the page, but it may or not contain a child component.

Figure: Basic Page Layout with Page-Level Actions and Informational Text shows panelPage facets (numbered 1 to 7) for laying out page-level actions and text.

Basic Page Layout with Page-Level Actions and Informational Text

Page layout. See Table 4-4 for descriptions.

Table: PanelPage Facets for Page-Level Actions and Informational Text shows the panelPage facets (as numbered in Figure: Basic Page Layout with Page-Level Actions and Informational Text), and the preferred children components that you could use in them.

PanelPage Facets for Page-Level Actions and Informational Text

No. Facet Description

1

actions

For page-level actions that operate on the page content. Typically use with a panelButtonBar to lay out a series of buttons, a processChoiceBar, or a selectOneChoice. Renders its children components below the page title, right-justified. The children components are also automatically repeated near the bottom of the page (above any text link versions of menu tabs and global buttons) on certain devices and skins.

2

contextSwitcher

A context switcher lets the user change the contents of the page based on the context. For example, when a user is viewing company assets for a department, the user can use the context switcher to switch to the assets of another department. All the pages will then change to the selected context. Typically use with a selectOneChoice component. The facet renders its child component on the same level as the page title, right-justified.

3

infoFootnote

For page-level information that is ancillary to the task at hand. Typically use with an outputFormatted component, with styleClass or styleUsage set to an appropriate value. The facet renders its child component near the bottom of the page, left-justified and above the infoReturn link.

4

infoReturn

For a "Return to X" link using commandLink. For the user to move quickly back to the default page of the active menu tab. The facet renders its child component near the bottom of the page, left-justified and above the text link versions of menu tabs and global buttons.

5

infoStatus

For page-level status information about the task at hand. Could also use to provide a key notation. A key notation is a legend used to define icons, elements, or terms used within the page contents. Typically use with an outputFormatted component, with styleClass or styleUsage set to an appropriate value. The facet renders its child component below the page title, left-justified.

6

infoSupplemental

For any other additional information. Typically use with a panelBox to show the information in an area offset by color. In the panelBox you could use for example panelList or outputFormatted text to provide additional information that might help the user, but is not required for completing a task. The facet renders its children components on the right side of the page, below the infoUser facet child component.

7

infoUser

For presenting user login and connection information. Typically use with an outputFormatted component, with styleClass or styleUsage set to an appropriate value. The facet renders its child component on the right side of the page, immediately below the menu bars.



Tip:

Like panelPage, the page component also lets you lay out an entire page with specific content areas. Unlike panelPage, you can bind the value of page to a menu model object to create the page's hierarchical menus—you don't have to bind individual menu components to a menu model object.

Page Body Contents

After you've set up the panelPage facets, create your forms, tables, and other page body contents inside the panelPage component. ADF Faces panel components (and others) help you to organize content on a page. Use Table: ADF Faces Layout and Panel Components to decide which components are suitable for your purposes.

For information about the component attributes you can set on each component, see the JDeveloper online help. For an image of what each component looks like, see the ADF Faces Core tag document at

http://www.oracle.com/technology/products/jdev/htdocs/partners/addins/exchange/jsf/doc/tagdoc/core/imageIndex.html

ADF Faces Layout and Panel Components

To... Use these components...

Align form input components in one or more columns, with the labels right-justified and the fields left-justified

panelForm

Arrange components horizontally, optionally specifying a horizontal or vertical alignment

panelHorizontal

Arrange components consecutively with wrapping as needed, horizontally in a single line, or vertically

panelGroup

Create a bulleted list in one or more columns

panelList

Lay out one or more components with a label, tip, and message

panelLabelAndMessage

Place multiple panelLabelAndMessage components in a panelForm

When laying out input component, the simple attribute on the input component must be set to true.

Place components in a container offset by color

panelBox

Typically use a single child inside panelBox such as panelGroup or panelForm, which then contains the components for display

Place components in predefined locations using facets

panelBorder

Lay out a series of buttons

panelButtonBar

Display additional page-level or section-level hints to the user

panelTip

Create page sections and subsections with headers

panelHeader, showDetailHeader

Add quick links to sections in long pages

Set the quickLinksShown attribute on panelPage to true

Let the user toggle a group of components between being shown (disclosed) and hidden (undisclosed)

showDetail

Let the user select and display a group of contents at a time

A ShowOne component with showDetailItem components

ShowOne components include showOneTab, showOneChoice, showOneRadio, and showOnePanel

Insert separator lines or space in your layout

objectSeparator, objectSpacer


Creating and Using a Backing Bean for a Web Page

In JSF, backing beans are JavaBeans used mainly to provide UI logic and to manage data between the web tier and the business tier of the application (similar to a data transfer object). Typically you have one backing bean per JSF page. The backing bean contains the logic and properties for the UI components used on the page. For example, to programmatically change a UI component as a result of some user activity or to execute code before or after an ADF declarative action method, you provide the necessary code in the page's backing bean and bind the component to the corresponding property or method in the bean.

For a backing bean to be available when the application starts, you register it as a managed bean with a name and scope in faces-config.xml. At runtime, whenever the managed bean is referenced on a page through a JSF EL value or method binding expression, the JSF implementation automatically instantiates the bean, populates it with any declared, default values, and places it in the managed bean scope as defined in faces-config.xml.

How to Create and Configure a Backing Bean

The Overview mode of the JSF Configuration Editor lets you create and configure a backing bean declaratively. Suppose you have a JSF page with the filename SRDemopage.jspx. Now you want to create a backing bean for the page.

To create and configure a backing bean as a managed bean:

  1. In the Application Navigator, double-click faces-config.xml to open it in the default mode of the JSF Configuration Editor.

  2. At the bottom of the editor, select the Overview tab to switch to the Overview mode, if necessary.

  3. In the element list on the left, select Managed Beans.

  4. Click New to open the Create Managed Bean dialog.

  5. In the dialog, specify the following for a managed bean:

    • Name: Enter a unique identifier for the managed bean (e.g., backing_SRDemopage). This identifier determines how the bean will be referred to within the application using EL expressions, instead of using the bean's fully-qualified class name.

    • Class: Enter the fully qualified class name (e.g., oracle.srdemo.view.backing.SRDemopage). This is the JavaBean that contains the properties that hold the data for the UI components used on the page, along with the corresponding accessor methods and any other methods (such as navigation or validation). This can be an existing or a new class.

    • Scope: This determines the scope within which the bean is stored. The valid scope values are:

      • application: The bean is available for the duration of the web application. This is helpful for global beans such as LDAP directories.

      • request: The bean is available from the time it is instantiated until a response is sent back to the client. This is usually the life of the current page. Backing beans for pages usually use this scope.

      • session: The bean is available to the client throughout the client's session.

      • none: The bean is instantiated each time it is referenced.

  6. Select the Generate Class If It Does Not Exist checkbox to let JDeveloper create the Java class for you. If you've already created the Java class, don't select this checkbox.


Note:

At this point, you haven't defined a strict relationship between the JSF page and the backing bean. You've simply configured a backing bean in faces-config.xml, which you can now reference via JSF EL expressions on a page. To define a strict relationship between a page and a backing bean, see How to Use a Backing Bean in a JSF Page.

What Happens When You Create and Configure a Backing Bean

If you select the Generate Class If It Does Not Exist checkbox, JDeveloper creates a new Java class using the fully qualified class name set as the value of Class. The new file appears within the Application Sources node of the ViewController project in the Application Navigator, as illustrated in Figure: Backing Bean for SRDemopage.jspx in the Navigator.

Backing Bean for SRDemopage.jspx in the Navigator

Application Sources folder in ViewController project

To edit the backing bean class, double-click the file in the Application Navigator (for example, SRDemopage.java) to open it in the source editor. If it's a new class, you would see something similar to Example: Empty Java Class Created by JDeveloper.

Empty Java Class Created by JDeveloper

package oracle.srdemo.view.backing;
 
public class SRDemopage {
    public SRDemopage() {
    }
}

In faces-config.xml, JDeveloper adds the backing bean configuration using the <managed-bean> element, as shown in Example: Registering a Managed Bean in the faces-config.xml File.

Registering a Managed Bean in the faces-config.xml File

<faces-config xmlns="http://java.sun.com/JSF/Configuration">
  ...
  <!-- Page backing beans typically use request scope-->
  <managed-bean>
    <managed-bean-name>backing_SRDemopage</managed-bean-name>
    <managed-bean-class>oracle.srdemo.view.backing.SRDemopage</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
  </managed-bean>
  ...
</faces-config>

Note:

For a backing bean to access the ADF Model binding layer at runtime, the backing bean could inject the ADF binding container. For information about how this is done, see Using ADF Data Controls and Backing Beans.

How to Use a Backing Bean in a JSF Page

Once a backing bean is defined with the relevant properties and methods, you use JSF EL expressions such as #{someBean.someProperty} or #{someBean.someMethod} to bind a UI component attribute to the appropriate property or method in the bean.

For example, the following code snippets illustrate value binding expressions and method binding expressions:

<af:inputText value="#{someBean.someProperty}"/>
..
<af:inputText disabled="#{someBean.anotherProperty}"/>
..
<af:commandButton action=#{someBean.someMethod}"/>
..
<af:inpuText valueChangeListener="#{someBean.anotherMethod}"/>

When such expressions are encountered at runtime, JSF instantiates the bean if it does not already exist in the bean scope that was configured in faces-config.xml.

In addition to value and method bindings, you can also bind the UI component's instance to a bean property using the binding attribute:

<af:commandButton binding="#{backing_SRDemopage.commandButton1}"

When the binding attribute of a UI component references a property in the bean, the bean has direct access to the component, and hence, logic in the bean can programmatically manipulate other attributes of the component, if needed. For example, you could change the color of displayed text, disable a button or field, or cause a component not to render, based on some UI logic in the backing bean.

To reiterate, you can bind a component's value attribute or any other attribute value to a bean property, or you can bind the component instance to a bean property. Which you choose depends on how much control you need over the component. When you bind a component attribute, the bean's associated property holds the value for the attribute, which can then be updated during the Update Model Values phase of the component's lifecycle. When you bind the component instance to a bean property, the property holds the value of the entire component instance, which means you can dynamically change any other component attribute value.

How to Use the Automatic Component Binding Feature

JDeveloper has a feature that lets you automatically bind a UI component instance on a JSF page to a backing bean property. When you turn on the Auto Bind feature for a page, for any UI component that you insert into the page, JDeveloper automatically adds property code in the page's backing bean, and binds the component's binding attribute to the corresponding property in the backing bean. If your backing bean doesn't have to modify the attributes of UI components on a page programmatically, you don't need to use the automatic component binding feature.

To turn on automatic component binding for a JSF page:

  1. Open the JSF page in the visual editor. Select