`

深入Facelets (一)简介

阅读更多

The web community is eagerly seeking a framework like Tapestry, backed by JavaServer Faces as the industry standard. While JavaServer Faces and JSP are meant to be aligned, Facelets steps outside of the JSP specification and provides a highly performant, JSF-centric view technology. Anyone who has created a JSP page will be able to do the same with Facelets and familiar XML-tag use. The difference is under the hood where all the burden of the JSP vendor API is removed to greatly enhance JSF as a platform and provide easy plug-and-go development without requiring JSP tag development.

JavaServer Faces UIComponents are first class citizens within Facelets; there's no need to develop extra objects to integrate. There's also no need to learn yet another XML schema to define your views.

Here's an example of how easy it is to define a view with Facelets:

  1. <html xmlns="http://www.w3.org/1999/xhtml"  
  2.       xmlns:h="http://java.sun.com/jsf/html"  
  3.       xmlns:c="http://java.sun.com/jstl/core">  
  4. <head>  
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />  
  6. <title>Hellotitle>  
  7. head>  
  8. <body>  
  9.     <form id="helloForm" jsfc="h:form">  
  10.         <h2>  
  11.             Hi. My name is Duke.  I'm thinking of a number from   
  12.             #{UserNumberBean.minimum} to #{UserNumberBean.maximum}.   
  13.             Can you guess it?   
  14.         h2>  
  15.         <img id="waveImage" src="wave.med.gif" />  
  16.            
  17.         <input type="text" jsfc="h:inputText" id="userNo"  
  18.                value="#{UserNumberBean.userNumber}"  
  19.                validator="#{UserNumberBean.validate}"/>  
  20.                   
  21.         <input type="submit" jsfc="h:commandButton" id="submit"  
  22.                action="success" value="Submit" />  
  23.         <p />  
  24.         <h:message showSummary="true" id="errors1" for="userNo"/>  
  25.         <p />  
  26.         <c:forEach begin="1" end="4" varStatus="v">  
  27.         #{view.viewId} #{v.index}<br/>  
  28.         c:forEach>  
  29.     form>  
  30.   
  31. body>  
  32. html>  

You may be thinking that the markup looks extremely familiar. That's the point. There's no need to learn another templating language or schema.

Why Use Facelets?

First and foremost, Facelets isn't dependent on a JSP container. This means that you can start using the new JSF 1.2 features without waiting for a JSP 2.1 container. There were some serious issues with combining JSF 1.1 and JSP use when it first came out. Many of these issues were highlighted in an article by Hans Bergsten titled, "Improving JSF by Dumping JSP." Reading that article is strongly recommended as a case for moving to JSF 1.2 and Facelets.

Secondly, Facelets is designer friendly. Taking from Tapestry's jwcid attribute, Facelets uses jsfc and proper namespaces to convert HTML elements to their associated JSF component. In the example above, jsfc (JSF Compilation) is used to tell the compiler to instead build a h:inputText component into the view.

Last to be mentioned here, Facelets is very light weight. Some of you may be familiar with Velocity's capabilities as a templating engine. Facelets has the same capabilities such that you can define and test JSF views without a Servlet container. The framework overhead is minimal and practical for production use. It also opens the doors for JSF use in deployments outside of servlets, including Portlets.

Here's how you create a new Facelet:

  1. // grab our FaceletFactory and create a Facelet   
  2. FaceletFactory factory = FaceletFactory.getInstance();   
  3. Facelet f = factory.getFacelet(viewToRender.getViewId());   
  4.   
  5. // populate UIViewRoot   
  6. f.apply(context, viewToRender);  

Short List of Features

Here's a short list of Faclet's current feature set:
  • Works with JSF 1.1 and JSF 1.2, including Sun's RI and Apache MyFaces.
  • Zero Tag development time for UIComponents
  • Fast Templating/Decorators for Components and Pages
  • The ability to specify UIComponent trees in separate files (UICompositions)
  • Line/Tag/Attribute precise Error Reporting
  • Specify Tags in Separate Files, even packaged with Jars
  • Full EL support, including Functions
  • Compile-time EL Validation
  • XML configuration files aren't necessary, but are available
  • Reserves the 'jsfc' attribute which acts the same as Tapestry's jwcid
    1. (Example: <input id="bar" type="text" jsfc="h:inputText" value="#{foo.bar}"/>)    
  • Plugable Decorators to really make designer's job easy
    1. (Example: transform <input type="text"/> to <h:inputText/> at compile time)    
  • Does *not* required any special RenderKits
  • Facelets isn't dependent on a Web Container

Why Facelets will Succeed

Everyone wants to be more designer friendly, and Tapestry seems to be the only choice developers are pursuing. On the other hand, JSF is the standard everyone would like to have happen, but JSF needs a more "pluggable" ViewHandler framework that is both designer and developer friendly.

Developers go through enough work defining UIComponents/Converters/Validators in their faces-config.xml, and Facelets only asks them to specify a name alias to plug their objects into their pages (no XML necessary). The key is ease of integration and development.

In conclusion, Facelets is a clean slate for correcting concerns with JSF. Templating, re-use, and ease of development are top priorities that will help bring developers on board with JSF as a suitable platform for large scale projects.

分享到:
评论

相关推荐

    facelets 教程

    ### Facelets 教程:深化理解 JavaServer Faces 的下一代视图技术 #### 一、Facelets:JavaServer ...对于希望构建高性能、高可用性的现代 Web 应用的开发者而言,Facelets 无疑是一个值得深入研究和掌握的强大工具。

    facelets中文教程(初级+高级)

    本教程将深入探讨Facelets的基础以及高级特性,旨在帮助初学者和有经验的开发者更好地理解和应用Facelets。 一、Facelets基础 Facelets作为JSF的默认视图描述语言,取代了原来的JSP(JavaServer Pages)。它提供了...

    facelets源码包

    Facelets是一种用于构建JavaServer Faces (JSF)应用程序的视图技术,它是JSF 2.0及更高版本的标准视图层表示。Facelets提供了一种声明式的方式来创建动态和交互式的用户界面,允许开发者使用XML或者XHTML语法来定义...

    facelets_demo

    Facelets 是一种用于构建用户界面的视图技术,主要在JavaServer Faces (JSF) 应用程序中使用。它提供了声明式的方式去定义页面结构和逻辑,使得开发者能够更高效地创建和维护Web应用程序的前端。在这个"facelets_...

    netbeans_Facelets_Seam_Ejb3编程入门

    《NetBeans Facelets Seam Ejb3编程入门》是一份详尽的指南,不仅涵盖了NetBeans IDE的基本配置和使用,还深入探讨了如何利用Facelets、Seam和EJB3技术开发企业级Java Web应用。对于希望使用这些技术进行开发的初学...

    Facelets Essentials - APRESS

    总而言之,《Facelets Essentials》是一本专为想要深入了解和掌握Facelets框架的开发者准备的指南。通过学习本书,开发者不仅能够提高开发JSF应用的效率,还能确保应用具有更好的性能和更高的代码质量。无论你是JSF...

    JSF与Facelets应用程序

    **Facelets** 是JSF的一种视图层技术,它取代了早期的JSP(JavaServer Pages)作为JSF应用的标准视图表示。Facelets以其XML为基础的语法和模板结构,提供了更清晰、更易于维护的视图创建方式。它支持组件重用,便于...

    Apress.Facelets.Essentials.May.2008

    总的来说,《Facelets Essentials》这本书为Java Web开发人员提供了一个深入学习Facelets的资源,涵盖了Facelets的基本概念、高级特性和实际应用,同时也可能涉及到与其他Web开发技术的比较,以帮助开发者做出最佳的...

    Apress - Definitive Guide To Apache Myfaces And Facelets (2008)

    根据提供的文件信息,我们可以推断出这是一本关于Apache MyFaces和Facelets的权威指南书籍。本书由多位作者合作完成,包括Zubin Wadia、Martin Marinschek、Hazem Saleh、Dennis Byrne等,并由Apress出版社于2008年...

    Facelets:jsf、primefaces、facelets、spring 集成、jstl、

    **Facelets:JSF、PrimeFaces、Facelets、Spring 集成与JSTL** Facelets 是一种视图层技术,它是JavaServer Faces (JSF) 框架的标准...通过深入研究这些文件,你可以学习到如何构建一个完整的、高效的Java Web应用。

    facelets.......................................

    通过阅读博客和研究这些布局文件,开发者可以深入理解Facelets的页面布局机制,以及如何根据需求调整和创建自定义布局。这些布局示例为实践提供了很好的起点,可以进一步探索和应用到实际项目中。

    WebApplicationFacelets-源码.rar

    一、Facelets简介 Facelets作为JSF的视图层技术,它取代了JSP成为JSF2.0及更高版本的默认视图表示语言。Facelets提供了更简洁、更易于维护的XML语法,允许开发者创建可重用的组件,并且具有更好的性能和开发效率。 ...

    WebApplicationFacelets:与 WebApplication 相同,但带有 facelets ..

    此外,运行示例应用并进行调试也是深入理解Facelets工作原理的好方法。 总的来说,WebApplicationFacelets是一个强调使用Facelets技术的Web应用示例,对于想要学习和掌握Java Web开发,特别是JSF和Facelets的开发者...

    JSF框架入门教程和JSF的jar包

    3. **编写第一个JSF页面**: 使用Facelets创建一个简单的Hello, World页面,了解组件的使用。 4. **Managed Bean的创建和使用**: 编写Managed Bean,处理页面请求和数据。 5. **调试和测试**: 运行应用,通过浏览器...

    jsf仿frame

    【JSF(JavaServer Faces)】 JSF是一种用于构建Web应用程序的JavaEE技术,它提供了用户界面组件、...开发者可以通过研究这个实例,深入理解JSF和Facelets的工作原理,以及如何利用它们来创建高效且可维护的Web应用。

    第一个JSF程序

    **JSF(JavaServer Faces)**是Java平台上用于构建Web应用程序的一种组件模型。它提供了一种面向对象的方式来创建用户界面,使得开发人员可以更轻松地处理...对于初学者,这将是一次深入了解Java Web开发的宝贵经历。

    深入掌握J2EE编程技术

    《深入掌握J2EE编程技术》是一本专为Java开发者设计的高级教程,旨在帮助读者深入理解并精通J2EE(Java Platform, Enterprise Edition)的各个核心组件和技术。J2EE,现已被更名为Java EE(Java Enterprise Edition...

    推荐经典《JSF入门》简体中文版教程

    二、Facelets简介 Facelets是JSF的标准视图层技术,用于生成HTML页面。与JSP相比,Facelets更易于维护,支持模板和组件重用。在Facelets中,开发者可以使用XML语法定义UI组件和布局,同时支持EL(Expression ...

    jsf入门,一个星期轻松掌握jsf框架

    Facelets是JSF的默认视图表示技术,它是一种XML-based模板语言,用于创建JSF组件树。Facelets支持组件重用、模板和可扩展性,使得视图层的维护更为方便。 ### EL(Expression Language) JSF使用EL表达式来访问和...

    JSF入门(一)

    在接下来的学习中,我们将深入探讨如何创建第一个JSF应用程序,配置开发环境,以及如何使用JSF组件和bean来构建动态的Web页面。同时,我们还将涉及JSF的错误处理、国际化以及与Spring等其他框架的集成。通过实践,你...

Global site tag (gtag.js) - Google Analytics