Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

3.3 Add Facelets and Seam UI Support

To support the Facelets and Seam UI frameworks, you must first bundle the necessary library JAR files in the application. Three JAR files go into the app.war archive's WEB-INF/lib directory because they contain tag definitions. Facelets requires the jsf-facelets.jar file; Seam needs the jboss-seam-ui.jar and jboss-seam-debug.jar files. An additional JAR file, jboss-el.jar, goes into the EAR file mywebapp.ear to support the JSF Expression Language (EL) in both the web module (app.war) and the EJB3 module (app.jar).

mywebapp.ear
|+ app.war
   |+ web pages
   |+ WEB-INF
      |+ web.xml
      |+ faces-config.xml
      |+ other config files
      |+ lib
         |+ jsf-facelets.jar
         |+ jboss-seam-ui.jar
         |+ jboss-seam-debug.jar
|+ app.jar
|+ lib
   |+ jboss-el.jar
   |+ jboss-seam.jar
|+ META-INF
   |+ application.xml
   |+ jboss-app.xml

To use Facelets and Seam's enhancements to JSF EL, you need to load a special view handler in the faces-config.xml file, which is located in the WEB-INF directory in the app.war (or in the resources/WEB-INF directory in the project source). The view handler renders HTML web pages from Facelets template and pages. This is the relevant snippet from the faces-config.xml file:

<faces-config>
  ... ...
  <application>
    <view-handler>
      com.sun.facelets.FaceletViewHandler
    </view-handler>
  </application>
<faces-config>

In a Facelets application, we typically use the .xhtml filename suffix for web pages since they are now XHTML files, not JSP pages. We have to tell the JSF runtime about this change in the web.xml file (in the same directory as the faces-config.xml file):

<web-app>
  ... ...
  <context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
  </context-param>
</web-app>

Finally, let's set up the Seam filter and resource servlet in the same web.xml file. The SeamFilter provides support for error pages, JSF redirects, and file upload. The Seam resource servlet provides access to images and CSS files in jboss-seam-ui.jar, which are required by Seam UI components. The resource servlet also enables direct JavaScript access to Seam components (Chapter 21).

<web-app>
  ... ...
  <servlet>
    <servlet-name>Seam Resource Servlet</servlet-name>
    <servlet-class>
      org.jboss.seam.servlet.ResourceServlet
    </servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>Seam Resource Servlet</servlet-name>
    <url-pattern>/seam/resource/*</url-pattern>
  </servlet-mapping>

  <filter>
    <filter-name>Seam Filter</filter-name>
    <filter-class>
      org.jboss.seam.web.SeamFilter
    </filter-class>
  </filter>

  <filter-mapping>
    <filter-name>Seam Filter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

</web-app>
  • + Share This
  • 🔖 Save To Your Account