Using MyFaces with Oracle JDeveloper 10g (10.1.3) Preview

Using MyFaces with Oracle JDeveloper 10g (10.1.3) Preview

Written by Jonas Jacobi, Oracle Corporation
February, 2005
Revision 1.0

Using MyFaces implementation and components

This HowTo explains how to use the MyFaces implementation and the MyFaces custom components with Oracle JDeveloper 10g (10.1.3) Preview and ADF Faces. This HowTo is divided into two parts - one that is explaining how to get MyFaces custom components installed within Oracle JDeveloper 10g (10.1.3), and the second part is covering how to get Oracle ADF Faces components up and running with the MyFaces implementation. For more information and HowTos, please, refer to the JDeveloper page on Oracle Technology Network (OTN).

Prerequisites
Using MyFaces custom components with JDeveloper
Using ADF Faces components with MyFaces
More information

Prerequisites

In order to follow this HowTo you need the Oracle JDeveloper 10g (10.1.3) Developer Preview, ADF Faces, and access to Internet.

Using MyFaces custom components with JDeveloper 10g (10.1.3) Developer Preview

MyFaces is an open source project that can be found under the umbrella of the Apache foundation. MyFaces is an alternative JavaServer Faces (JSF) implementation to the JSF Reference Implementation (RI) provided by Sun. In most cases developers will be satisfied using what ever JSF implementation is provided with the tools. Oracle JDeveloper 10.1.3 Developer Preview has built-in support for the Sun Reference Implementation. In the JDeveloper 10.1.3 Developer Preview developers are restricted in that they cannot switch out the provided JSF implementation with another implementation such as MyFaces. In the production release of JDeveloper 10.1.3 developers will be able to switch out the by default provided RI and use a JSF implementations of their choice.

Here follows the steps to setup Oracle JDeveloper 10.1.3 Developer Preview to use the MyFaces extension library contain a set of custom JSF components with the Sun RI:

  1. First download JDeveloper 10g (10.1.3) Developer Preview if you do not already have installed.
  2. Then download the MyFaces binary files from the MyFaces site or directly from the MyFaces build system.
    Note: If you decide to take a build from the build you should download the file - myfaces-1.0.8.tgz. In this example we are using the file located on the build system.
  3. Extract the file and locate a file that is called "myfaces-extension.jar" for the 1.0.8 version of MyFaces. This file is located in the [extract_location]\myfaces-1.0.8\lib.
  4. Start JDeveloper 10.1.3 Developer Preview.
  5. Click on the Tools menu and select the Manage Libraries... option.
  6. Select the JSP Tag Libraries tab.
  7. Click on the Users node in the left pane, and then on the New button at the bottom of the list.
  8. Locate and select the myfaces-extension jar file described in step 3. Click Open.
  9. You should now have a node that in the left pane says "x 0.9.0" and the right side should be populated with information about the MyFaces extension TLD.


     
  10. Change the display name from "x" to "MyFaces Extension".
  11. Before you close the dialog make sure you check the "Execute Tags in JSP Visual Editor" option to enable live rendering of these custom components.

Image illustrating MyFaces within JDeveloper

You are now done with installing MyFaces components in to JDeveloper. If you need to add these components to an already existing project you will have to add the tag library to your Project properties. If you create an application or page from scratch you have the option to add them in the New Page wizard.

For more information about MyFaces please visit the Apache MyFaces website. For more information about Oracle's JSF offering please visit the JDeveloper and Oracle ADF Faces EA pages on OTN.

Using ADF Faces components with the MyFaces implementation

Due to the aforementioned restriction in the Oracle JDeveloper 10.1.3 Developer Preview developers have to first create their ADF Faces application with the RI as a base. When the application is done and ready for deployment the developer can swap out the RI libraries and replace them with the MyFaces libraries. To illustrate how to setup an application built with ADF Faces components with the MyFaces implementation we will use the ADF Faces demo bundle.
Here is how you do it:

  1. Download the ADF Faces complete standalone install (adf-faces-ea13.zip) from OTN.
  2. Extract the file and locate the adf-faces-demo.zip file. Should be located at the root of the adf-faces-ea12 directory.
    Note: The file adf-faces-demo.zip is a demo WAR with missing third party libraries. It has been renamed to a ZIP so that users don't try to run it without the missing libraries.
  3. Extract adf-faces-demo.zip. We'll call the directory you unzip it into [DEMO_HOME].
  4. In the [DEMO_HOME]/WEB-INF/lib directory remove the following libraries:
     
    • jstl.jar
    • commons-logging-1.0.3.jar
    • commons-digester-1.5.jar
    • commons-collections-2.1.jar
    • commons-beanutils-1.6.jar
       
  5. Get the missing MyFaces JSF 1.0.8 JAR files - download the tgz file 'myfaces-1.0.8.tgz'. Extract the following jars to [DEMO_HOME ] /WEB-INF/lib (WinZip's "Use Folder Names" option should be unchecked):
    • All 'commons-*.jar'
    • All 'myfaces-*.jar'
    • jakarta-oro.jar
    • jstl.jar
    • jsp-2.0.jar
       

Before we are ready to deploy there are some changes needed in the WEB.XML file. The web.xml is located in the [DEMO_HOME ] /WEB-INF directory. We need to include the StartupServletContextListener class.

Note: This class is needed to be able to parse the faces-config.xml file and should be implemented into to the myfaces-core.tld instead of having it defined in the web.xml file.

  1. Add the following code snippet just below the <web-app> tag at the top of your web.xml file:

    <listener>
       <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
    </listener>
     
  2. You also have to remove the following lines at the bottom of the web.xml provided by the ADF Faces demo bundle:

     <!-- ADF Faces Tag Library -->
    <taglib>
    <taglib-uri>http://xmlns.oracle.com/adf/faces/EA13</taglib-uri>
    <taglib-location>/WEB-INF/af.tld</taglib-location>
    </taglib>

    <taglib>
    <taglib-uri>http://xmlns.oracle.com/adf/faces/EA13/html</taglib-uri>
    <taglib-location>/WEB-INF/afh.tld</taglib-location>
    </taglib>

    <!-- Faces Core Tag Library -->
    <taglib>
    <taglib-uri>http://java.sun.com/jsf/core</taglib-uri>
    <taglib-location>/WEB-INF/jsf_core.tld</taglib-location>
    </taglib>

    <!-- Faces Html Basic Tag Library -->
    <taglib>
    <taglib-uri>http://java.sun.com/jsf/html</taglib-uri>
    <taglib-location>/WEB-INF/html_basic.tld</taglib-location>
    </taglib>

    Note: These references are not needed and should not be in this file. This will be fixed in a subsequent release of our ADF Faces demo bundle.
     
  3. Rezip the result into a file named 'adf-faces-myfaces-demo.war'. Make sure the directory structure is the same as it was in adf-faces-demo.zip.

Now the WAR is ready to go. For more information about the demo war please follow the instructions on the installation page.

Running from within JDeveloper

  1. Create a new Application workspace.
    • Select File -> New -> General -> Workspaces -> Application workspace.
  2. In the new workspace, create a project from a WAR file.
    • Select File -> New -> General -> Projects -> Project from WAR File.
  3. In step 1 of the wizard, name the project "demo" and accept the default directory location.
  4. In step 2, locate the WAR file (adf-faces-myfaces-demo.war).
  5. Click Finish. This will expand the WAR file contents into your new project directory. You should now see your new project in the Application Navigator.
  6. Take a few seconds to familiarize yourself with the various files in this application. You'll find the adf-faces-config.xml along with other files in the WEB-INF directory.
  7. Make sure you enable "J2SE 1.4 Assertions" in the project properties under the Compiler category.
    • Select 'Tools -> Project Properties -> Compiler' and check 'Enable J2SE 1.4 Assertions'
  8. Add the J2EE library
    • Select 'Tools -> Project Properties -> Libraries' and add the 'J2EE' library
  9. Click OK to close the Project Properties dialog.
  10. You can now start the demo by running index.jspx.

More Information

For more information about JSF and Oracle JDeveloper 10g (10.1.3) Developer Preview please visit the Oracle JDeveloper home page at Oracle Technology Network.

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy