InfoQ

News

JavaServer Faces 2.0 Composite Components

Posted by Charles Humble on Nov 04, 2008 02:56 PM

Community
Java
Topics
JCP Standards ,
Web 2.0 ,
Web Frameworks
Tags
AJAX ,
JSF ,
Java EE

JavaServer Faces 2.0 is the first major update of the Java EE standard specification since it was first released back in 2004. As such JSF 2.0 is a significant overhaul of the JSF specification and aims to address a number of the key pain points developers encounter when working with the web framework. Key changes include:

 

  1. Replacing JSP with an alternative viewing technology based on Facelets.
  2. Provision of a standardized resource handling mechanism: Many components require artifacts such as JavaScript files, images or CSS elements in order to render correctly. JSF 1.x has no facility for handling these so component developers typically have to develop their own mechanism.
  3. Relocatable resources: Resources can be told where to render themselves, and this rendered location may be different from the resource tag placement in the view. This allows custom components and JSF pages to render resource references in the proper location so your CSS file reference can be included in the <head> section even if the component is included in the body.
  4. System events: A publish/subscribe event model that supports events which are not specific to a particular application, but rather stem from specific points of time during the execution of a JSF application. Both UI components and the Application object (which is a singleton) can receive system events.
  5. Additional scopes: A view scope and a component scope have been added. Support for a conversation scope is expected to be included through the Web Beans API.
  6. Standardization of a "project stage" parameter: Project stage provides a means to affect JSF behaviour based on a set of pre-defined enums which may be set via a context parameter or JNDI. For example additional debug information might be displayed in a browser during development and suppressed in production. Defined stages are production, development, unit test, system test and extension with production as the default value. At run time you can query the application object for the configured value by calling Application.getProjectStage().
  7. Reducing XML dependency by exploiting annotations and default values.
  8. Extending the AJAX support introduced in JSF 1.2.

A number of these “big ticket” items come together to address one of the major pain points for developers working with JSF 1.x - the complexity of building custom components. With JSF 1.x a component author has to follow a number of steps to make a custom component available for use in markup pages. At a minimum, the component author has to implement both a JSP or Facelets Tag Handler, and provide a renderer for the component, both of which also require appropriate entries in the faces-config.xml file. Facelets, a JSF-centric alternative to JSP widely used by JSF developers, improves matters somewhat by providing support for templating via composite components. This approach involves creating an XHTML page that contains the template mark-up and components, and then using these as components in other pages. Any valid Facelet XHTML page can be used as a component, and unlike using Facelets with JSF 1.x, composite components in JSF 2 act as true UIComponents and can thus support validators, converters, and listeners (both action and value change). The composite components are handled as resources and can therefore exploit the new standard resource mechanism. So, for example, if a Facelet mark-up file named MenuPanel.html resides inside a resource library called ezcomp, then page authors can use this component by declaring the xml namespace xmlns:ez="http://java.sun.com/jsf/composite/ezcomp" and including the tag <ez:menuPanel /> in their pages.

The JSF 2.0 expert group have released Draft 2 for JSF 2.0 which is available for download from the JCP site. An implementation of the draft is also available. The specification is expected to reach final draft status by the end of the year.

No comments

Watch Thread Reply

Educational Content

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.