This blog entry opens a series of short articles describing my studying of facelets and attempts to apply it in our platform.

Problem using JSF with JSPs.

First of all, why does our platform need facelets? Currently we are using JSPs with custom JSF tags inside so what’s the problem with combining JSF and JSP? There are lots of good articles related to this topic, so I won’t be repeating their authors. I’ll just briefly sum up main idea.

  • JSP’s goal is to produce static and dynamic content based on HTML/scriptlet mixture; technically speaking JSP produces a servlet. JSP page is processed in one pass from top to bottom, with JSP action elements processed in the order in which they appear in the page.
  • JSF maintains component tree where components are created, asked to process their input (if any), and then asked to render themselves. These three actions must be processed separately in a well-defined order.

The root cause of all confusion is that the life cycle of the JSF component model is independent from the life cycle of the JSP-produced servlet. So using JSF components via JSF custom tags lead to the problem that component creation and rendering happens in parallel, causing all kinds of bugs (see “Improving JSF by Dumping JSP”).

Ok…then how do we (still) manage to survive with JSPs in our platform? Apart from God’s help we are relying on custom-made hacks. Hacks are integrated in all parts of JSP-JSF bridge; if some day I have a courage I could possibly write an article describing most interesting ones. All in all, main drawback of these hacks is that view layer in our application became slow, clumsy and what’s even worse – hard to maintain and upgrade. And it’s getting worse with each iteration.

What’s so special with facelets?

Facelets is a view technology for JSF that replaces the standard view handler which deals with JSP pages. It is built from the ground up with the JSF component life cycle in mind. With Facelets, you produce templates that build a component tree, not a servlet. Facelets is a powerful templating system that allows you to define JSF views using HTML-style templates, reduces the amount of code necessary to integrate components into the view  (see “Facelets fits JSF like a glove” for more detailed information).
By using facelets in our platform we’ll become closer to native JSF life cycle. Fast templating and possibility to create reusable composition components will allow us to keep DRY principle while developing new pages. Developing web part of our application should significantly reduce programmer efforts and (who knows?) may become a real joy for him (isn’t it what a Real Developer wants ;-) ?)

Email this Share this on Facebook Share this on LinkedIn Tweet This! RSS feed for comments on this post. TrackBack URL

Leave a comment