---
title: "facelets+tomahawk+jsf环境配置"
author: "eneasy"
date: "2008-08-17T18:03:26Z"
tags: []
slug: "facelets-tomahawk-jsf"
draft: false
lastmod: "2008-08-17T18:03:26Z"
id: 229001
url: "https://eneasy.iteye.com/blog/229001"
---

facelets+tomahawk+jsf 环境配置

 

 

先下载 facelets1.1.4 、 tomahawk1.1.6 、 jsf sun ri 1.2\_08-b06-FCS 以及 tomahawk-facelets-taglib1.1.6 。

下面分别是它们的下载网站：

facelets1.1.4 ： https://facelets.dev.java.net/

tomahawk1.1.6: [http://myfaces.apache.org/tomahawk/](http://myfaces.apache.org/tomahawk/)

jsf sun ri 1.2: http://java.sun.com/javaee/javaserverfaces/

tomahawk-facelets-taglib1.1.6: [http://code.google.com/p/tomahawk-facelets/](http://code.google.com/p/tomahawk-facelets/)

 

jsf sun ri 是 jsf 的参考实现，提供了 jsf 的基本功能和常用的组件， tomahawk 则是兼容于 jsf 规范并在其基础上提供了大量的扩展组件 ,facelets 为 jsf 提供了强大的模板和方便地自定义组件的支持。为了将 tomahawk 和 facelets 集成使用，需要将 tomahawk-facelets-taglib 放到 WEB-INF/lib 目录下即可。 tomahawk 依赖很多第三方的 jar 包，可以参照 tomahawk-example 中的 WEB-INF/lib 目录，将这些依赖的包也放在项目 WEB-INF/lib 路径下。如图 :

![](../../upload/picture/pic/20059/88147e1f-5606-3833-be8b-9bd4855cba47.jpg)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

web.xml 文件的配置 :

 

&lt;? xml version = *'1.0'* encoding = *'UTF-8'* ?&gt;

 

&lt;! DOCTYPE web-app PUBLIC

"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

"http://java.sun.com/dtd/web-app\_2\_3.dtd" &gt;

 

 

&lt; web-app &gt;

 

&lt;!-- facelets --&gt;

&lt; context-param &gt;

    &lt; param-name &gt; javax .faces.DEFAULT\_SUFFIX &lt;/ param-name &gt;

    &lt; param-value &gt; . xhtml &lt;/ param-value &gt;

&lt;/ context-param &gt;

 

&lt;!-- Faces Servlet --&gt;

&lt; servlet &gt;

    &lt; servlet-name &gt; FacesServlet &lt;/ servlet-name &gt;

    &lt; servlet-class &gt; javax .faces. webapp .FacesServlet &lt;/ servlet-class &gt;

    &lt; load-on-startup &gt; 1 &lt;/ load-on-startup &gt;

&lt;/ servlet &gt;

 

&lt;!-- Faces Servlet Mapping --&gt;

&lt; servlet-mapping &gt;

    &lt; servlet-name &gt; FacesServlet &lt;/ servlet-name &gt;

    &lt; url-pattern &gt; \*. jsf &lt;/ url-pattern &gt;

&lt;/ servlet-mapping &gt;

&lt;!-- tomahawk --&gt;

&lt; filter &gt;

    &lt; filter-name &gt; MyFacesExtensionsFilter &lt;/ filter-name &gt;

    &lt; filter-class &gt;

       org . apache . myfaces . webapp .filter.ExtensionsFilter

    &lt;/ filter-class &gt;

    &lt; init-param &gt;

         &lt; param-name &gt; uploadMaxFileSize &lt;/ param-name &gt;

         &lt; param-value &gt; 20m &lt;/ param-value &gt;

         &lt; description &gt; Set the size limit for uploaded files.

           Format: 10 - 10 bytes

                           10k - 10 KB

                           10m - 10 MB

                            1g - 1 GB

          &lt;/ description &gt;

      &lt;/ init-param &gt;

&lt;/ filter &gt;

 

&lt;!-- extension mapping for adding &lt;script/&gt;, &lt;link/&gt;, and other resource tags to JSF-pages --&gt;

&lt; filter-mapping &gt;

   &lt; filter-name &gt; MyFacesExtensionsFilter &lt;/ filter-name &gt;

      &lt;!-- servlet -name must match the name of your javax .faces. webapp .FacesServlet entry --&gt;

   &lt; servlet-name &gt; FacesServlet &lt;/ servlet-name &gt;

&lt;/ filter-mapping &gt;

&lt;!-- extension mapping for serving page-independent resources ( javascript , stylesheets , images, etc.) --&gt;

&lt; filter-mapping &gt;

   &lt; filter-name &gt; MyFacesExtensionsFilter &lt;/ filter-name &gt;

   &lt; url-pattern &gt; /faces/myFacesExtensionResource/* &lt;/ url-pattern &gt;

&lt;/ filter-mapping &gt;

&lt;!-- custom component --&gt;

&lt; context-param &gt;

     &lt; param-name &gt; facelets .LIBRARIES &lt;/ param-name &gt;

     &lt; param-value &gt;

         /WEB-INF/mycustom .taglib .xml

     &lt;/ param-value &gt;

&lt;/ context-param &gt;

 

&lt;/ web-app &gt;

 

可以不使用 tomahawk-facelets-taglib.jar ，而是手动编写 tomahawk.taglib.xml 组件描述文件并在 web.xml 中将路径告知 facelets, 即设置参数 facelets .LIBRARIES 的值。

 

faces-config .xml 文件的配置 :

&lt; faces-config &gt;

&lt;!-- facelets --&gt;

&lt; application &gt;

    &lt; view-handler &gt;

          c om.sun.facele ts.FaceletViewHandler

    &lt;/ view-handler &gt;

&lt;/ application &gt;

&lt;!-- navigation --&gt;

&lt;!-- back bean --&gt;

 

&lt;/ faces-config &gt;

 

完成上述配置后，就可以发挥 jsf 、 tomahawk 和 facelets 的强大功能了 , 开发的项目可以在 tomcat6.0.16 中运行，也可以使用其它的服务器。