Apache myfaces介紹和配置
JSF是一個(gè)新的基于MVC模型的web應(yīng)用框架技術(shù)。在概念和特征方面,尤其是組件方面,超過(guò)了著名的Struts框架。而myfaces是Apache軟件基金的一個(gè)項(xiàng)目,它實(shí)現(xiàn)了JSF框架。同樣sun公司也有一個(gè)參考實(shí)現(xiàn) JSF RI。但是myfaces比JSF RI提供了更多的組件和特征。
可以參考:http://myfaces.apache.org/index.html
http://java.sun.com/j2ee/javaserverfaces/
開發(fā)基于JSF的web應(yīng)用程序可以使用下列IDE(筆者已知):
myEclipse(Eclipse插件) ,默認(rèn)同時(shí)支持JSF RI 和myfaces
http://www.myeclipseide.com/
Exadel(Eclipse插件) 默認(rèn)支持JSF RI
http://www.exadel.com/
Java Studio Creator 默認(rèn)支持JSF RI
oracle 的jDevelop 也支持JSF但是有自己的特色組件。
使用myfaces
myfaces官方的發(fā)行版本myfaces1.1.0中有四個(gè)jar包,分別 myfaces-api.jar,myfaces-impl.jar,tomahawk.jar,myfaces-all.jar。myfaces-all.jar包括了前三個(gè)jar包的所有
內(nèi)容。myfaces-api.jar,其實(shí)是JSF RI。tomahawk.jar是包含了myfaces實(shí)現(xiàn)的特色組件,可以單獨(dú)使用,在已經(jīng)使用JSF的web應(yīng)用程序中加入這個(gè)包就可以myfaces的組件,但是
無(wú)法使用myfaces的其他特征,如和struts-tiles結(jié)合。
筆者在myeclipse,tomcat5.0.28和jdk1.4.2中成功運(yùn)行基于myfaces的web應(yīng)用程序。并且沒用了筆者以前提到的JSF中文輸入亂碼的問題。但是在tomcat5.5.9和JDK1.5update4中
沒用調(diào)試成功,tomcat啟動(dòng)報(bào)錯(cuò),頁(yè)面無(wú)法顯示。在web\lib下加入myfaces的jar包后,還要在web.xml中加入如下片斷。
<?xml version="1.0" encoding="UTF-8"?> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee <context-param> <listener> <!-- 支持文件上傳功能,程序沒用文件上傳功能,這個(gè)也就不需要了--> <filter-mapping> 參考:
<web-app xmlns="
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<filter>
<filter-name>extensionsFilter</filter-name>
<filter-class>
org.apache.myfaces.component.html.util.ExtensionsFilter
</filter-class>
<init-param>
<description>
Set the size limit for uploaded files. Format: 10 - 10
bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
</description>
<param-name>uploadMaxFileSize</param-name>
<param-value>100m</param-value>
</init-param>
<init-param>
<description>
Set the threshold size - files below this limit are
stored in memory, files above this limit are stored on
disk.
Format: 10 - 10 bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
</description>
<param-name>uploadThresholdSize</param-name>
<param-value>100k</param-value>
</init-param>
<!--
<init-param>
<param-name>uploadRepositoryPath</param-name>
<param-value>/temp</param-value>
<description>Set the path where the intermediary files will be stored.
</description>
</init-param>
-->
</filter>
<filter-name>extensionsFilter</filter-name>
<url-pattern>*.faces</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>extensionsFilter</filter-name>
<url-pattern>/faces/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
</web-app>
要在頁(yè)面使用myfaces組件,請(qǐng)?jiān)陧?yè)面中加入。
<%@ taglib uri="
http://wiki.apache.org/myfaces/How_to_add_MyFaces_support_to_a_Sun_JSF_RI_application
http://wiki.apache.org/myfaces/Installation_and_Configuration
http://myfaces.apache.org/index.html
http://myfaces.apache.org/gettingstarted.html
聯(lián)系客服