您的位置:首页 > 运维架构 > Apache

Apache myfaces介绍和配置

2013-07-24 14:48 302 查看
Apache myfaces介绍和配置

JSF是一个新的基于MVC模型的web应用框架技术。在概念和特征方面,尤其是组件方面,超过了著名的Struts框架。而myfaces是Apache软件基金的一个项目,它实现了JSF框架。同样sun公司也有一个参考实现 JSF RI。但是myfaces比JSF RI提供了更多的组件和特征。

可以参考:http://myfaces.apache.org/index.html

http://java.sun.com/j2ee/javaserverfaces/

开发基于JSF的web应用程序可以使用下列IDE(笔者已知):

myEclipse(Eclipse插件) ,默认同时支持JSF RI 和myfaces

http://www.myeclipseide.com/

Exadel(Eclipse插件) 默认支持JSF RI

http://www.exadel.com/

Java Studio Creator 默认支持JSF RI

oracle 的jDevelop 也支持JSF但是有自己的特色组件。

使用myfaces

myfaces官方的发行版本myfaces1.1.0中有四个jar包,分别 myfaces-api.jar,myfaces-impl.jar,tomahawk.jar,myfaces-all.jar。myfaces-all.jar包括了前三个jar包的所有

内容。myfaces-api.jar,其实是JSF RI。tomahawk.jar是包含了myfaces实现的特色组件,可以单独使用,在已经使用JSF的web应用程序中加入这个包就可以myfaces的组件,但是

无法使用myfaces的其他特征,如和struts-tiles结合。

笔者在myeclipse,tomcat5.0.28和jdk1.4.2中成功运行基于myfaces的web应用程序。并且没用了笔者以前提到的JSF中文输入乱码的问题。但是在tomcat5.5.9和JDK1.5update4中

没用调试成功,tomcat启动报错,页面无法显示。在web\lib下加入myfaces的jar包后,还要在web.xml中加入如下片断。

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<context-param>

<param-name>javax.faces.CONFIG_FILES</param-name>

<param-value>/WEB-INF/faces-config.xml</param-value>

</context-param>

<listener>

<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-mapping>

<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>

要在页面使用myfaces组件,请在页面中加入。

<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>

参考:

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: