InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

JavaServer Faces 2.0 Composite Components

Posted by Charles Humble on Nov 04, 2008

Sections
Architecture & Design,
Development,
Enterprise Architecture
Topics
Web 2.0 ,
Web Frameworks ,
Java ,
JCP Standards
Tags
JSF ,
AJAX ,
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

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.