# Configuring JSF Projects

OEPE provides a JSF project facet with the following functionality that you can use to configure your JSF projects:

- Support for Oracle WebLogic Server shared library

- Support for downloadable user library

- Library version validation

- JSP templates

- Notification that files will be deleted during uninstall of the facet

To add JSF capabilities to your Web project with Oracle Weblogic Server runtime support:

1. Right-click your Web project in Project Explorer, select Properties from the drop-down menu, and then select Targeted Runtimes from the list on the Properties dialog. Ensure that you are using Oracle WebLogic Server 11gR1 (10.3.2) or later as your target runtime.

2. On the Properties dialog, highlight Project Facets node and select JavaServer Faces facet from the list, specifying either version 1.2 or 1.1.

3. On the same Properties dialog, ensure that WebLogic Web App Extensions facet with one of 1.3.2, 1.3.1 or 1.3 versions is selected, and then click Further configuration available. This opens the Modify Faceted Project > JSF Capabilities dialog.

4. Complete this dialog by specifying JSF implementation library information, as well as configuration file name and servlet parameters.

   When competing the Modify Faceted Project > JSF Capabilities dialog, you have the following two options with regards to which JSF implementation library to add to your project:

   1. WebLogic Shared Library - this option is available only when your project is configured with WebLogic Web App Extensions facet. If you click Manage WebLogic Shared Libraries, a Preferences > Shared Libraries dialog opens allowing you to modify library information, as well as to remove existing and add new libraries to your project.

   2. User Library - allows you to either download a specific version of the JSF library (you will be prompted to accept an appropriate license), or add the library from a local install (JAR file).

   The system validates the selected library and will notify you if any of the following occurs:

   - The required JSF class cannot be found in the library (for example, if you select a non-JSF user library).

   - The selected library version and the facet version are not compatible (for example, if a JSF 1.1 library is selected for a JSF 1.2 facet).

   - The library version cannot be read.

   You can click Download library to initiate the download of the user library of your choice. Note that if your machine is located inside of a network, which requires a proxy to access outside resource such as the Internet, the download may fail. In this case, reconfigure your Eclipse IDE proxy settings using Window > Preferences > General > Network Connections, and try again.

   If you select Include libraries with this application, the libraries will be copied to your project's `WEB-INF/lib` directory at publish time.

5. Click OK on the Modify Faceted Project > JSF Capabilities dialog to save your changes.

Upon completion, the following configurations of your project have taken place:

- `web.xml` has been configured depending on whether you chose Sun-RI or Apache MyFaces implementation.

- The following JSF templates are installed:

  - `faces-config.xml` configuration file in your project's `WebContent/WEB-INF/config` directory.

  - `index.jsp` JSP file in your project's WebContent directory.

  - `application.properties` resource bundle in your project's `src/resources` directory.

- `faces-config.xml` file is configured as follows:

## Supported JSF Libraries and Versions

OEPE provides support for JSF 1.2 and 1.1 versions.

The following table maps the supported JSF versions to three types of libraries:

Supported JSF Versions

Supported JSF Version | Oracle WebLogic Server Shared Library | Downloadable Library | User Library
--- | --- | --- | ---
JSF 1.2 | Supported | Supported: MyFaces, Sun-RI | Supported
JSF 1.1 | Supported | Supported: MyFaces, Sun-RI | Supported

## Creating a Faces Configuration File

OEPE provides support for Faces configuration resource file by allowing you to create and edit a Faces Configuration File.

To create a new Faces configuration file for your JSF dynamic Web project:

1. Right-click the Project Explorer and choose New > Other. Alternatively, choose select New > Other from the top-level menu's File or from the AppXplorer view drop-down menu. This opens the New dialog.

2. On the New JSF Configuration File > JSF Configuration File Properties dialog specify the location for your new file (in the `WebContent/WEB-INF` folder) and provide a file name.

3. Click Finish to save your changes.

   A new Faces configuration XML file containing the faces-config declaration is created with the given name and in the specified location.

   The project's `web.xml` file is updated with a new path string in the value of the `javax.faces.CONFIG_FILES` context parameter. If the `javax.faces.CONFIG_FILES` context parameter does not exist, it is created.

Alternatively, in the Project Explorer you may right-click your JSF project's Faces Configuration directory and choose New JSF Configuration File from the drop-down menu.

## Using the Faces Configuration Node

Using your JSF dynamic Web project's Faces Configuration node, you can create the following:

- Managed beans

- Navigation rules

- Converters

- Validators

### Creating a New Managed Bean

You can create s managed bean in your Web application to bind the bean properties and business logic to the user interface components.

To create a managed bean:

1. In the Project Explorer, expand your JSF dynamic Web project's Faces Configuration node, right-click Managed Beans, and then select New Managed Bean. This opens the New Managed Bean Wizard dialog which allows you to create a managed bean from an existing or a newly created Java class.

2. If you choose to create a managed bean from an existing class:

   1. On the New Managed Bean Wizard > Java Class Selection dialog click Browse to open the Select Type dialog. In this dialog, start typing the bean class name in the Select entries field, then select the class from the list and click OK.

   2. Proceed by clicking Next on the New Managed Bean Wizard > Java Class Selection dialog to open the New Managed Bean Wizard > Managed Bean Configuration dialog.

   3. Click Next to review the summary page, and then click Finish. Notice that your new bean has been added under the Faces Configuration > Managed Beans node.

3. If you choose to create a new Java class for your managed bean:

   1. On the New Managed Bean Wizard > Java Class Selection dialog select Create a new Java class, and then click Next to open the New Managed Bean Wizard > Java Class dialog.

   2. Complete this dialog, and then click Next to open the New Managed Bean Wizard > Managed Bean Configuration dialog. On this dialog, click Next to proceed to the summary page, and then click Finish. Notice that your new bean has been added under the Faces Configuration > Managed Beans node

### Creating a New Navigation Case

You create navigation rules to link Web pages. Each navigation rule can contain one or more navigation cases.

To define navigation rules and cases:

1. In Project Explorer, expand your JSF dynamic Web project's Faces Configuration node, right-click Navigation Rules, and then select New Navigation Rule. This opens the New Navigation Rule dialog which allows you to create a new navigation rule by providing an either new or existing JSP source page, and then defining destination pages.

2. If you choose to create your navigation rule using an existing JSP page as a source page:

   1. On the New Navigation Rule dialog click Browse for JSP to open the Select JSP File dialog and select the page.

   2. Define one or more navigation cases from the source page by clicking New on the New Navigation Rule dialog to open the New Navigation Case dialog.

      Note that the destination page for your new navigation case can be an existing JSP page that you select using the Select JSP File dialog, or a new JSP page.

   3. If you need to, create a new JSP. Click Create a New JavaServer Page on the New Navigation Case dialog to open the New JavaServer Page > JavaServer Page dialog. Using this dialog, select a package and provide a name for your new JSP page, and then click Next.

   4. On the next New JavaServer Page > Select JSP Template dialog select a template to serve as initial content of your new JSP page, and then click Finish.

      Click OK on the New Navigation Case dialog.

3. If you choose to create your navigation rule using a newly create JSP page as a source page, click Create a New JavaServer Page on the New Navigation Rule dialog to open the New JavaServer Page > JavaServer Page dialog.

   Notice that your new navigation rule has been added under the Faces Configuration > Navigation Rules node.

### Creating a New Converter

You can create a converter for your Web application. A converter is used in the conversion model, where each component can be associated with the server-side model object data. The component data can have two views: model and presentation. You can enable conversion of the data between the model view and the presentation view.

To create a converter:

- In the Project Explorer, expand your JSF dynamic Web project's Faces Configuration node, right-click Converters, and then select New Converter. This opens the New Converter dialog where you can define a new converter.

Notes:

- The implementation class of your converter must be an extension of the `javax.faces.convert.Converter`.

- The implementation class of your converter must be an extension of the `javax.faces.convert.Converter`.

### Creating a New Validator

To create a validator for your JSF project:

1. In the Project Explorer, expand your JSF dynamic Web project's Faces Configuration node.

2. Right-click Validators, and then select New Validator. This opens the New Validator dialog where you define the new validator.

Note: The implementation class of your validator must be an extension of the `javax.faces.validator.Validator`.

## Using the Faces Configuration Editor

The Faces configuration editor allows you to modify the `faces-config.xml` file to define and edit page navigations, managed beans, components, converters, validators, render-kit, as well as to perform other element configurations.

You use the editor as follows:

In the Project Explorer, right-click your JSF dynamic Web project's Faces Configuration node, and select Open. This opens the Faces Configuration Editor' start page. This page enables access to useful resources such as documentation and help topics.

Use the following tabs to edit the Faces configuration:

- Overview tab that Figure 26 shows offers the compact presentation of all editable information. Double-clicking an element opens a relevant editor tab to enable editing.

- Overview tab that Figure 26 shows offers the compact presentation of all editable information. Double-clicking an element opens a relevant editor tab to enable editing.

  You can create navigation rules by dragging and dropping JSP pages onto the canvas in one of the following ways:

  - Directly from the Project Explorer.

  - From the Palette by selecting Nodes > Page to open the Select JSP File dialog that Figure 28 shows.

  To draw links between pages, use the Palette's Link tool.

  You can reposition elements on the canvas. In addition, you can modify the elements' properties using the Quick Edit editor that displays properties of the selected element.

- Managed Bean tab allows you to modify configuration of managed beans in your project.

- Component tab enables editing of information about components, converters, validators, and render kits that you defined for your project.

- Others tab lets you edit various Faces configurations that are not covered in any of the other tabs.

- Source tabs provides access to the faces-config.xml file itself.

## Understanding JSF Resource Bundles

If you would like your JSF application to use a resource bundle, you need to register it with the application. For JSF projects, when they are configured with the JSF facet, an application.properties file is automatically created in the src/resources folder. As one of the uses of a resource bundle is to enable localization, a loadBundle tag is typically added to each JSP page you want to localize:

    <f:loadBundle basename="resources.application" var="bundle"/>