JSF VS Tapestry

来源:互联网 发布:数据恢复大师免费版 编辑:程序博客网 时间:2024/04/29 17:54

1.性能方面

JSF

从测试数据可以看出在只使用JSFJSF自定义组件的情况下,webmail demo应用速度最快,200用户并发访问的响应时间为1.8秒,基本上可以达到servlet + jsp的性能。

使用JSF + 5Facelet composition组件的情况下,webmail demo应用仍可达到200用户并发访问的响应时间为2.6秒的性能。

使用JSF + 20Facelet composition组件的情况下,webmail demo应用可达到200用户并发访问的响应时间为3.1秒的性能。

如果在业务层方法没有大的效率问题、并在压力较大的页面适当使用缓存的情况下,JSF应用程序可以达到在dell 2850机器上100-200并发5秒内响应的性能

Tapestry

从测试数据可以看到tapestry在使用相同数量框架自身提供组件的情况下,运行效率比JSF明显要低一些,但也算是在可以接受的范围内。

 

2.开发方面

JSF

JSFservlet API进行了封装,程序员在使用组件做JSF应用程序的开发时基本上不需要直接操作HttpRequestHttpResponse,并且对用户输入验证,手机等其它设备(通过rendererKit),多语言(通过资源文件方式)和换肤(通过rendererKit)的支持都有相应的封装,可以方便的实现。目前开源的组件库有MyFaces,ADF等可以使用,其中有些组件内置AJAX支持。

开发工具中IBM WebSphere Studio,Oracle JDeveloper 10gFaceIDEIDEJSF应用开发提供可视化编辑支持。下面是对JSF自定义组件和JSF+facelet composition组件开发进行比较

 

JSF自定义组件开发:

JSF自定义组件由java代码和tag库文件组成,开发难度应该与现有I2SS组件开发的难度基本一致,JSF自定义组件通过自定义标记构造页面,在页面上增加组件的数量对性能有较大的影响。

 

JSF + facelet composition组件开发:

facelet composition组件在个性化、重用方面对JSF提供了很好的补充。通过编写tag库文件,使用facelet可以把多个JSF自定义组件组合成facelet composition组件,或者把几个facelet composition组件组合成新的facelet composition组件,这个过程不需要开发或设计人员编写Java代码。facelet composition组件是live模式运行时生成,从测试结果上看组件数量对性能的影响不大

 

JSF已经作为j2ee5标准的一部分,具体可以查看http://java.sun.com/javaee/5/javatech.html

 

学习曲线上,开发难度与组件基本一致,只要写过组件或写过servlet+jsp的人,加上适当培训,一周内都可掌握JSFTapestry开发

 

Tapestry

组件和页面的开发过程完全一致,都是由模板、page/component classspecification文件组成。IDE方面目前有开源社区开发的eclipse插件SpindleTapestry Palette可用,对开发效率有一定的提升。

3.集群支持方面

JSF

目前在I2SS上做的集群实验是使用apache+jboss来实现,结构是apache做集群前端实现stick sessionjboss做应用服务器。

I2SS架构应用程序Session中放入的对象并不能全部串行化,所以在做集群时只能使用粘贴会话方式(stick session)实现,这样容易出现的情况是如果一台机器down掉,这台机器上的所有在线用户都会无法继续当前的会话。如果用户重新发起登录请求,任务会转移到其它正常工作的机器上。如果down掉的机器重新恢复,转移到其它机器上的用户不能重新使用这台新启动的机器,只有新发起的用户请求和在线用户调用session.invalidate()显式退出后,工作才会转移到新启动的机器上,这样负载的均衡时间会比较长。I2SS架构应用程序可以通过更改框架层,将现有放入session中的对象实现串行化,并且将不能串行化的对象放到session以外的地方来实现使用session replication的集群模式。

 

JSF上做的集群实验是使用apache+jboss来实现,支持stick sessionsession replication两种模式。stick session模式的结构和讨论如上述,session replication的结构是apache做集群前端,通过jbossTreeCache实现session replication。在编写JSF程序时要把放入会话中的backing-beans实现串行化,如果一台机器down掉,在线用户的会话会转移到其它正常工作的机器上,对于用户的感受来说可能是速度变慢,但是不会出现会话断掉的情况。如果down掉的机器重新恢复,TreeCache通过网卡或文件系统完成session replication的过程后,在线用户的任务就可以实现与机器未down时相同的负载均衡状态。如果想减少网卡或文件系统的I/O操作,可以通过集群分区来实现。

 

Tapestry

Tapestry本身提供两种state持久方式:传统的session方式和client-side方式。状态保存在session中的情况下,实现集群和JSF方式一样,需要session replication。保存在client-side的情况下,有一些局限性,但是可以实现无状态的应用,自动支持集群。

 

 

4.对于I2SS组件与JSF组件混合使用的说明

 

JSF组件应用程序是标准J2EE应用程序,JSF组件对servlet API提供了封装,同时也提供了直接得到servlet上下文的方法,所以I2SS组件与JSF组件的混合使用与现在已经实现的邮件系统中servlet+JSPI2SS组件的混合使用方法是一样的,都可以用手动创建EbiContext实例的方法来实现。

 

* I2SS组件要和tapestry组件混合使用的话比较困难,但是可以在tapestry组件中调用I2SS的业务处理方法。

 

5.目前JSF标准的进展情况,以及行业的支持情况

JSF 体系结构
JavaServer Faces
MVC 实现
JSF
的主要优势之一就是它既是 Java Web 用户界面标准又是严格遵循模型-视图-控制器 (MVC) 设计模式的框架。用户界面代码(视图)与应用程序数据和逻辑(模型)的清晰分离使 JSF 应用程序更易于管理。为了准备提供页面对应用程序数据访问的 JSF 上下文和防止对页面未授权或不正确的访问,所有与应用程序的用户交互均由一个前端“Faces”servlet(控制器)来处理。



1JavaServer Faces MVC 实现

JSF已经作为j2ee5标准的一部分,具体可以查看http://java.sun.com/javaee/5/javatech.html

因为 JavaServer Faces 是一种标准的 Java 技术,因此软件开发工具完全能够为 JavaServer Faces 提供高级的集成开发工具支持。多个供应商现在不同程度地支持 JSF 开发,这大大提高了 JSF 的易用性和功能。OracleSun Borland IBM 都为 JavaServer Faces 提供了开发环境。由于开发工具供应商在竞相提供更好、更简单和更多的开发环境,因此基于 IDE JSF 开发拥有美好的前景!

目前JSR 127: JavaServer Faces处于final状态
JSR 252: JavaServer Faces 1.2处于In Progress状态
Facelets
处理Preview Draft状态

JSF技术已经作为J2EE5的一部分可以在J2EE5preview版本中使用,预计J2EE5正式发布后,所有的应用服务器提供商都会提供对JSF技术的内建支持。但JSFFaclet技术并不依赖于容器和JDK,现阶段JSF已可以在Jboss4.0+JDK1.4.2的环境中投入使用。



根据JSR-252官方网站上的描述

JavaServer Faces 1.2是对JavaServer Faces 1.1的增强

 

JavaServer Faces 1.2 provides a minimal enhancement of the JavaServer Faces 1.1 specification. It is not a new feature JSR. The primary goal of this JSR is handling the Faces side of the JSP/Faces alignment issues addressed in the parallel JSR-245. Please consult that JSR for details on the primary goal. Following is a list of secondary goals that will be addressed only if the primary goal is reached, and only if they can be addressed without delaying the schedule.

 

根据JSR-245官方网站上的描述

JSP2.1会改进JSP2.0的条件语言EL,以便JSF1.2更好的使用

JSP technology is focused on simplifying the generation of dynamic web content. The JSP 2.0 specification (JSR-152) substantially extended the technology by integrating a simple yet powerful expression language, simplifying the tag extension API, and enhancing the pure XML syntax, among other important enhancements. These enhancements greatly reduced the learning curve of the technology, warranting a major version number upgrade.

The scope of JSP 2.1 is much narrower and focuses on better alignment with the next release of JavaServer Faces.

JavaServer Faces 1.0 (JSR-127) defines a standard framework for building User Interface components, and builds on top of JSP 1.2 technology. Because JSP 1.2 technology does not have an integrated expression language and because the JSP 2.0 EL does not meet all of the needs of JSF, a new expression language was developed for JSF 1.0. The JSF EG attempted to make the language as compatible with JSP 2.0 as possible but some differences were necessary. The JSF EG agreed that the JSF 1.0 EL will be phased out in the next release of the JSF specification in favor of the JSP 2.1 expression language. It is a goal, therefore, of JSP 2.1 to enhance the expression language to meet the needs of JSF technology. Many of these enhancements are likely to be useful in other contexts as well.

 

webmail demo程序现在基于J2EE1.4开发,使用的JSF+Facelet组件,是基于JSF1.1的实现Apache MyFaces1.1.1组件

J2EE5包含的是JSF1.2servlet2.5,Facelet的新的draft版本是使用JSF1.2,如果迁移可能遇到的问题是:
Apache MyFaces
项目会在JSF1.2标准final draft以后开发相应的用JSF1.2版实现的MyFaces组件,所以现在使用的JSF组件不用更改,不过需要等JSF1.2版组件发布,所需时间不确定,如果其它厂商比如Oracle,IBMJSF1.2版组件发布的比较快,也可考虑使用

Facelet
组件中使用的EL可能需要更改,如果重用做得比较好,改动涉及的工作量不会很大

相关资源:
http://jcp.org/en/jsr/detail?id=245

http://jcp.org/en/jsr/detail?id=252
http://myfaces.apache.org/api/index.html



6.facelet对设计个性化及重用的支持情况


1)
定义基本的layout模板页面如上图所示

 

2)然后编写出文件夹列表面板页和邮件列表面板页

文件夹列表面板页MessageListPanel.xhtml代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<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:f="http://java.sun.com/jsf/core"

      xmlns:z="http://www.qualcomm.com/jsf/core"

      xmlns:c="http://java.sun.com/jstl/core"

      xmlns:fn="http://java.sun.com/jsp/jstl/functions"

      xmlns:t="http://myfaces.apache.org/tomahawk"

      xmlns:a="http://www.arc-mind.com/jsf">

 

THIS TEXT WILL BE REMOVED

<ui:composition>

    <h:form>

 

        <h:dataTable id="items" value="#{mailUserDataBean.folders}" var="folder"

            rowClasses="oddRow, evenRow" headerClass="tableHeader">

           

            <a:column entity="${folder}" fieldName="name" backingBean="${mailUserDataBean}"/>

 

        </h:dataTable>

 

    </h:form>

</ui:composition>

THIS TEXT WILL BE REMOVED AS WELL

 

</html>

 

邮件列表面板页MessageListPanel.xhtml代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<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:f="http://java.sun.com/jsf/core"

      xmlns:z="http://www.qualcomm.com/jsf/core"

      xmlns:c="http://java.sun.com/jstl/core"

      xmlns:fn="http://java.sun.com/jsp/jstl/functions"

      xmlns:t="http://myfaces.apache.org/tomahawk"

      xmlns:a="http://www.arc-mind.com/jsf">

 

 

<ui:composition>

 

        <h:dataTable id="messages" value="#{mailUserDataBean.messages}" var="message"

            rowClasses="oddRow, evenRow" headerClass="tableHeader">

           

            <a:column entity="${message}" fieldName="from" backingBean="${mailUserDataBean}"/>

            <a:column entity="${message}" fieldName="subject" backingBean="${mailUserDataBean}"/>

            <a:column entity="${message}" fieldName="sentDate" backingBean="${mailUserDataBean}"

                      sort="${false}"/>

 

        </h:dataTable>

 

        <br />

        <h:commandLink id="logout4" action="#{mailUserDataBean.logout}">

            <f:verbatim>logout</f:verbatim>

        </h:commandLink>

 

 

</ui:composition>

 

 

 

 

</html>

 

3) 然后用facelet composite组件定义出要替换为从邮件服务器取出的导航内容部分:index.xhtml页面代码如下:

// composition组件定义和要使用的模板

<ui:composition template="/WEB-INF/layout/layout.xhtml">

//文件夹列表

    <ui:define name="navigation">

        <a:FolderListPanel />

    </ui:define>

//邮件列表

    <ui:define name="content">

        <h:form>

            <a:MessageListPanel />

        </h:form>

    </ui:define>

</ui:composition>

 

定义后页面如上图所示

文件夹列表面板页和邮件列表面板页作为标记可以被重新使用或组合

如本例所示,使用facelet可以方便的定义新的composition组件,重用已有的compositionJSF组件

性能比较:

组件量 测试类型  Transaction  JSF   JSF+Facelet   Tapestry  Max   Min   Avg     Max   Min   Avg     Max   Min   Avg  5个组件 200并发无汇聚点  获取登陆页面时间   0.750   0.006   0.059     0.224   0.012   0.043     3.665   0.006   0.081   登陆+显示列表时间   0.973   0.058   0.429     4.813   0.047   0.103     3.345   0.188   0.265    200并发有汇聚点  获取登陆页面时间   0.124   0.006   0.019      0.207   0.012   0.038     3.155   0.010   0.099   登陆+显示列表时间   3.757   0.306   1.783     4.816   0.057   2.687     4.083   0.340   2.322    10个组件 200并发无汇聚点  获取登陆页面时间   0.316   0.007   0.049      0.422   0.012   0.053     0.941   0.006   0.049   登陆+显示列表时间   1.225   0.060   0.383     4.533   0.051   0.121     0.547   0.196   0.253    200并发有汇聚点  获取登陆页面时间   0.262   0.006   0.017     0.225   0.012   0.036     3.735   0.010   0.059   登陆+显示列表时间   4.162   0.302   2.008     5.074   0.201   2.804     4.434   0.348   3.284    20个组件 200并发无汇聚点  获取登陆页面时间   0.629   0.007   0.189     0.310   0.012   0.034     4.623   0.007   0.431   登陆+显示列表时间   2.644   0.061   0.801     0.985   0.052   0.111     5.733   0.232   0.936    200并发有汇聚点  获取登陆页面时间   0.073   0.005   0.014     0.177   0.012   0.031     2.278   0.010   0.052   登陆+显示列表时间   6.375   0.319   2.976     5.250   0.208   3.150     10.812   0.681   5.539