Weblog

Using facelets with ADF Faces

Create a new application and a new project in Jdeveloper. Download the following libraries:

Unzip the facelets library. I’ve copied the adf facelets jar to the facelets folder, this is not necessary, but keeps things together.

Open project properties of your view project, go to libraries, add a new facelets library. Include the following four jars:

Facelets library

In libraries make sure you have to following four libraries added:
Libraries

Next go to the JSP Tag libraries section and add the tag libraries for ADF Faces components, ADF Faces HTML, JSF Core and JSF HTML.

Tag libraries

Add the following to public_html/WEB-INF/web.xml

<context -param>
  <param -name>oracle.adf.view.faces.ALTERNATE_VIEW_HANDLER</param>
  <param -value>com.sun.facelets.FaceletViewHandler</param>
</context>
<context -param>
  <param -name>javax.faces.DEFAULT_SUFFIX</param>
  <param -value>.xhtml</param>
</context>

Add the following servlet mapping to web.xml, otherwise the url opened in your browser will not be correct when you run the page from jdeveloper.

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

Next, create a xhtml page. If you specify a .xhtml extension in the html wizard, it will not use the correct extension you specify. Instead, jdeveloper will add .html after your file name.

Xhtml file

To solve this you can either rename the file using the file menu of jdeveloper, or you can create general file, instead of an html file.

Next edit page1.xhtml

< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      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">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></meta>
    <title>untitled1</title>
  </head>
  <body>
    <ui :composition template="/WEB-INF/layout/layout.xhtml">
      </ui><ui :define name="header">
        <h :o utputText value="My header"/>
      </ui>
      <ui :define name="content">
        <af :o utputText value="My content"/>
        <h :o utputText value="My Footer"/>
      </ui>

  </body>
</html>

Finally well create a layout page which can be used to define the overall laypout foryou’re your pages. Add the following to public_html/WEB-INF/layout/layout.xhtml:

< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></meta>
    <title>layout</title>
  </head>
  <body>
    <div id="header">
      <ui :insert name="header"/>
    </div>
    <div id="content">
      <ui :insert name="content"/>
    </div>
  </body>
</html>

You can now run your page by selecting the page and rightclick run:
Run xhtml

Share and Enjoy:
  • del.icio.us
  • Google Bookmarks
  • DZone
  • LinkedIn
  • SphereIt
  • StumbleUpon
  • Technorati

9 Responses to “Using facelets with ADF Faces”

  1. sebastien pouillet Says:

    Cool Andrej. Thank you very much. I was planning on evaluating integration between the two. I will try that and it will certainly save me a lot of time !

  2. JDeveloper & Oracle ADF » Using facelets with ADF Faces Says:

    [...] Original post by Andrej Koelewijn [...]

  3. peter n saurugger Says:

    thanks, Andrej, very helpful. anybody has this working with JSF1.2?

  4. peter n saurugger Says:

    one issue I encountered with this setup is that facelet custom tags (taglibs referenced in facelets.LIBRARIES context-param in web.xml) cannot be called inside of ADF tags

  5. peter n saurugger Says:

    update: facelets and ADF now respect each other: all I had to do was replace the with

    in the templates and pages, and I wrapped my custom facelets tag libraries in ,

    and the world is happy …

  6. peter n saurugger Says:

    sorry, lost the tags:

  7. peter n saurugger Says:

    afh:html xmlns

    af:subform

  8. cobaasta Says:

    The Adf facelets library “adf-facelets.jar” was the key to success! Without this Weblog, i swould still search for a solution… Thanx

  9. javakias Says:

    Excellent work! Just congrats and thank you for providing such useful info to the community!

Leave a Reply

Technology