JavaServer Faces 留个记号

来源:互联网 发布:淘宝天猫超市怎么投诉 编辑:程序博客网 时间:2024/04/29 05:05

What is JavaServer Faces?

JavaServer Faces (JSF) is an application framework for creating Web-based user interfaces. If you are familiar with Struts (a popular open source JSP-based Web application framework) and Swing (the standard Java user interface framework for desktop applications), think of JavaServer Faces as a combination of those two frameworks. Like Struts, JSF provides Web application lifecycle management through a controller servlet; and like Swing, JSF provides a rich component model complete with event handling and component rendering.

In a nutshell, JSF eases Web-based application development because it:

  • Lets you create user interfaces from a set of standard, reusable server-side components
  • Provides a set of JSP tags to access those components
  • Transparently saves state information and repopulates forms when they redisplay
  • Provides a framework for implementing custom components
  • Encapsulates event handling and component rendering so you can use standard JSF components or custom components to support markup languages other than HTML
  • Lets tool vendors develop IDEs for a standard Web application framework


Besides being a conceptual combination of Struts and Swing, JSF is a direct competitor to Microsoft's WebForms. The frameworks are very similar, both in concept and implementation. And because JSF represents a standard for Java-based Web application frameworks, tool vendors can concentrate on developing IDEs for JSF instead of developing an IDE for one of approximately 35 existing Java-based Web application frameworks, including Struts.

Note: Struts developers needn't worry; although JSF and Struts have much in common, JSF will not make Struts obsolete. See Resources for a discussion of an integration strategy for Struts and JavaServer Faces.

Currently, JSF is an early access (EA) release, and, as a result, is somewhat immature. The specification leaves some functionality unspecified, and the specification and reference implementation are currently out of sync, with the former specifying new syntaxes and functionality not yet implemented in the latter. On the other hand, JSF is mature enough for you to write code against—although much of that code is guaranteed to be obsolete (see the disclaimer below)—and the reference implementation is fairly complete and relatively bug-free. You can download the JSF specification, the reference implementation, two sample applications, and a JSF tutorial from Resources.

The two articles in this series provide a code-intensive introduction to JavaServer Faces. In this article, I begin with a short discussion of the JSF lifecycle and then dive into some example code that illustrates implementation of Web-based user interfaces with JSF and how you can take advantage of built-in validation. In Part 2, I will explain more advanced JSF concepts such as: implementing custom validation; using model objects; internationalization; creating custom components; and finally, delegating event handling and rendering so you can use components to generate markup languages other than HTML.

Disclaimer: The code discussed in this article was written against the EA2 JSF reference implementation. As mentioned above, the specification and reference implementation are in a state of flux, and therefore, the code in this article is guaranteed to be obsolete in the near future; however, the code works as advertised with the EA2 reference implementation and was tested with both Tomcat 4.0.6 (the latest production release of Tomcat) and Resin 2.1.6. Furthermore, you can read the JSF specification until the cows come home, but to really grasp the concepts, you must ruminate over some code.

Resources

  • Download the source code that accompanies this article
    http://www.javaworld.com/javaworld/jw-11-2002/jsf/jw-1129-jsf.jar
  • "A First Look at JavaServer Faces," David Geary (JavaWorld):
    • Part 1Learn how to implement Web-based user interfaces with JSF (November 2002)
    • Part 2Explore JavaServer Faces components (December 2002)
  • An integration strategy for Struts and JavaServer Faces
    http://www.mail-archive.com/struts-dev@jakarta.apache.org/msg08457.html
  • Download the JSF specification, the reference implementation, two sample applications, and a JSF tutorial from
    http://java.sun.com/j2ee/javaserverfaces
  • Browse the JavaServer Pages section of JavaWorld's Topical Index
    http://www.javaworld.com/channel_content/jw-jsp-index.shtml
  • Browse the Enterprise Java section of JavaWorld's Topical Index
    http://www.javaworld.com/channel_content/jw-enterprise-index.shtml
  • David Geary's Java Design Patterns column in JavaWorld
    http://www.javaworld.com/columns/jw-java-design-patterns-index.shtml
  • Visit JavaWorld's Enterprise Java discussion
    http://forums.devworld.com/webx?50@@.ee6b80a
  • Sign up for JavaWorld's free weekly Enterprise Java email newsletter
    http://www.javaworld.com/subscribe
  • You'll find a wealth of IT-related articles from our sister publications at IDG.net

原创粉丝点击