April 18, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

JSF 2.0 Views: Hello Facelets, Goodbye JSP

  • March 1, 2010
  • By Sangeetha S, Nitin KL, Ananya S
  • Send Email »
  • More Articles »

JavaServer Faces (JSF) is a Java component UI framework for building dynamic pages for a web application. JSF technology provides an API for creating, managing, and handling UI components and a tag library for using components within a web page. The new release of JavaServer Faces, JSF 2.0, is a major release for the specification, and it will be part of the Java Enterprise Edition 6 platform. This latest release has several interesting features that make the development and deployment of JSF applications simple and easy.

Unlike JSF 1.x versions, which use JavaServer Pages (JSP) for views, JSF 2.0 mandates support for Facelets as the view technology for JSF pages. Like JSP, Facelets are an implementation of View Declaration Language (VDL), which allows developers to declare UI components in different presentation technologies using HTML templates. However, because the Facelets view technology has been designed specifically to leverage the features of JSF, Facelets provide JSF developers with a simpler, more powerful programming model than JSP. That is why beginning with JSF 2.0 Facelets will replace JSP (JSF 2.0 has retained JSP support only for backward compatibility).

In this article, we explore what makes Facelets superior to JSP for JSF applications, as well as how JSF 2.0 supports them. We use a demo application and provide some code samples to highlight the power of this new technology.

Facelets Features

In Facelets, the pages are compiled to an abstract syntax component tree, which gets built to a UIComponent hierarchy during runtime. The Facelets tags don't need declaration in a tag library descriptor (TLD) file. The attributes in the tag are dynamic; they automatically get mapped to the properties. One of the main Facelets features not available in JSP is page templating. In addition, Facelets are faster in execution than JSPs.

Facelets pages are authored using XHTML, and they provide good expression language (EL) support. Facelets also leverage the concept of XML namespaces to support these tag libraries:

  • JSF HTML Tag Library
  • JSF Core Tag Library
  • JSTL Core Tag Library
  • JSTL Functions Tag Library
  • JSF Facelets Tag Library
The idea behind authoring Facelets using XHTML is to make them portable across diverse development platforms. Because JSF is authored using XHTML pages, which conform to DTD, Facelets have the .xhtml extension. To use Facelets in a JSF application, you must set the following context parameters in web.xml:

<context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
    <param-value>true</param-value>
</context-param>


The first parameter defines .xhtml as the default suffix for all view pages containing JSF content. The true value of the second parameter causes the JSF implementation to ignore XML comments in the Facelets page.


Tags: JavaServer Faces, JSF, JavaServer Pages, Facelets, JSP



Page 1 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel