分享

Apache myfaces介绍和配置

 duduwolf 2005-10-02

Apache myfaces介绍和配置

JSF是一个新的基于MVC模型的web应用框架技术。在概念和特征方面,尤其是组件方面,超过了著名的Struts框架。而myfaces是Apache软件基金的一个项目,它实现了JSF框架。同样sun公司也有一个参考实现 JSF RI。但是myfaces比JSF RI提供了更多的组件和特征。
可以参考:http://myfaces./index.html 
http://java./j2ee/javaserverfaces/
开发基于JSF的web应用程序可以使用下列IDE(笔者已知):
myEclipse(Eclipse插件)  ,默认同时支持JSF RI 和myfaces
http://www./
Exadel(Eclipse插件)  默认支持JSF RI
http://www./
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./xml/ns/j2ee" xmlns:xsi="http://www./2001/XMLSchema-instance" version="2.4"

xsi:schemaLocation="http://java./xml/ns/j2ee   http://java./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./tomahawk" prefix="t"%>

参考:
http://wiki./myfaces/How_to_add_MyFaces_support_to_a_Sun_JSF_RI_application
http://wiki./myfaces/Installation_and_Configuration
http://myfaces./index.html
http://myfaces./gettingstarted.html

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约