转载请注明出处(Cooper的专栏 http://blog.csdn.net/cooper_lyt)
JSF只是一个API定义,具体的实现有很多如Sun的和apache的myFaces
而Sun的JSF实现已经加入到了JavaEE5.0中去了。所以在JavaEE5.0的项目中使用了Sun的实现,但于由JSF的可伸缩性,其它的实现中有很多很好的功能和组件(不知道叫组件是否合适,这东东有点Delphi组件的意思,所以就这么叫了),好东西怎么可以不用,所以我们要在使用Sun的JSF实现的同时使用其它实现的组件。
- Myface的扩展tomahawk
apache的myFaces里有很多Sun实现中没有的组件如inputDate、dataScroller 等(具体的方法和其它的组件我会另写文章说明)所以一定要加入我的项目。步骤如下
1.你需要下载apache myfaces上的tomahawk.jar文件并放到项目的ClassPath中去。
注意:如果你项目的ClassPath中没有commons-el.jar 这个包的话会报以下错误:
threw exception: java.lang.NoClassDefFoundError: org/apache/commons/el/Logger org/apache/commons/el/Logger
所以还要把这个包加到项目的ClassPath中,单从名子上看这个大概是Myfaces用来记录EL表达示日志的包(未考证),因为MyEclipse中有Myface的库所以在myEclipse的安装目录中查找这个文件就能找到这个包,拷到项目的ClassPath中就不会出现这个错误了。
2.在web.xml中设置myFaces的过滤器,如下:
- <!-- apache myfaces tablib -->
- <filter>
- <filter-name>MyFacesExtensionsFilter</filter-name>
- <filter-class>
- org.apache.myfaces.webapp.filter.ExtensionsFilter
- </filter-class>
- <init-param>
- <param-name>maxFileSize</param-name>
- <param-value>20m</param-value>
- </init-param>
- </filter>
- <!-- extension mapping for adding <script/> , <link/> , and other resource tags to JSF-pages -->
- <filter-mapping>
- <filter-name>MyFacesExtensionsFilter</filter-name>
- <!-- servlet-name must match the name of your javax.faces.webapp.FacesServlet entry -->
- <servlet-name>Faces Servlet</servlet-name>
- </filter-mapping>
- <!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.) -->
- <filter-mapping>
- <filter-name>MyFacesExtensionsFilter</filter-name>
- <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
- </filter-mapping>
3.在使用MyFaces组件的页中加入标签库的引用
xhtml方式的(由于facelets必须使用xhtml或jspx的页面文件):注意 xmlns:th=http://myfaces.apache.org/tomahawk 这句就是
- <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:th="http://myfaces.apache.org/tomahawk"
- xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en">
jsp方式的
<%@ taglib uri= "http://myfaces.apache.org/tomahawk " prefix= "th"%>
4.使用 <th:inputDate value="#{varValue}" rendered="#{varIsDate}"></th:inputDate>
OK,加入完成。
转载请注明出处(Cooper的专栏 http://blog.csdn.net/cooper_lyt)