In the previous articles, we have seen JSF applications working with JSP. So far every thing works fine, but if you read the article 'Improving JSF by Dumping JSP', we can find a whole lot of issues with using JSF and JSP together. Even though the purpose of the both these technologies is to render response to a request, they do it in a completely different way. JSF has a well defined Request Processing Life Cycle to render the response. It creates a component tree and ask the components render themselves. JSP on the other hand, render the tags, in the order they appear in the page. These conflicting approaches, results in unexpected behavior of the application and makes these technologies not a good natural combination. Another issue with JSF is, it is not a designer friendly. That means, JSF pages are difficult to view using browser or web designing tools like Dreamweaver. Because of these all these issues, the web community was eagerly waiting for an alternative view technology for JSF. It seems like search for the alternative view technology has come to an end with Facelets. Facelets is implemented as a JSF ViewHandler, so it is easy to configure facelets for a JSF application. It also comes with a powerful templating system, which reduces number of pages in an application.
Facelets is a templating language built from the ground up with the JSF component life cycle in mind. Some of the compelling features of Facelets are:
- Composition Components ( Specifying UIComponent trees in a separate file)
- EL Support (including Function)
- Compile Time EL evaluation.
- No new xml configuration files
- Aliasing Components with jsfc
Support for code reuse through templating is an important considerations for developers to adopt JavaServer Faces as the platform for large scale projects. By supporting these features, Facelets reduces the time and effort on development and deployment.
Facelets comes with a simple but powerful set of UI Tag Library
In this JSF Facelets tutorial, we will see how to set up the Facelets development environment used to build and run examples.
Just like any other Java Web application, we need
- Eclipse IDE for Java EE Developers (I am using version 3.5.1)
- JSF Facelets Tools - WTP Incubator project .
- Apache Tomcat 6.0
Download WTP Incubator Project Components (Get the Facelets Tools which works with the Galileo Release of WTP), unzip it to a local folder, copy the folder in <local folder>/eclipse/features in to the features folder of eclipse IDE. Likewise copy the <local folder>/eclipse/plugins in to the plugins folder of eclipse IDE.
Adding User Libraries in eclipse
Select Windows->Preferences->Java->Build Path->Use Libraries. Click on the New button. In the wizard, give the User library name as JSF1.2(SUN_RI). Click OK. Now select JSF1.2(SUN_RI) and click on Add JARs..Add the following jars
We have to create two more user libraries. (Click 'Next' below to continue..)