Wednesday, May 28, 2008

Using Facelets along with JSP in a JSF application

I wanted to use Facelets for some pages in an existing JSP/JSF application.
To achieve this I had to perform the following steps:

  • Download Facelets and copy the jsf-facelets.jar into your WEB-INF/lib directory
    If you use maven you can include the following dependency in your pom:
            <dependency>
                <groupId>com.sun.facelets</groupId>
                <artifactId>jsf-facelets</artifactId>
                <version>1.1.14</version>
            </dependency>
  • Add the FaceletViewHandler to the faces-config.xml file.
    <application>
        ...
        <view-handler>
            com.sun.facelets.FaceletViewHandler
        </view-handler>
    </application>
  • Define which pages should be handled by Facelets, i.e. urls ending with '.xhtml'. Add the following snippet to your web.xml:
        <context-param> 
                <param-name>facelets.VIEW_MAPPINGS</param-name> 
                <param-value>*.xhtml</param-value> 
        </context-param>
  • For a useful debug-screen, you should also add the following snippet to your web.xml:
        <context-param>
            <param-name>facelets.DEVELOPMENT</param-name>
            <param-value>true</param-value>
        </context-param>
  • 1 comment:

    1. Super!! Thanks very much!! Very good!! God Bless U in Jesus Name!

      ReplyDelete

    Related Posts Plugin for WordPress, Blogger...