I see that from JSF2.0 onwards Facelets view definition language is the preferred view definition language and not JSP which has been deprecated as a legacy fall back. I want to understand why Facelets is preferred over JSP as the view definition language from JSF2.0 onwards ? I know that JSP also has some templating behavior which is the main driving point for adopting Facelets .
P.S: I have been through this post on stackoverflow but I do not think it answers my question. Hence posting this as a separate question .
True, JSP has some templating capabilities, but the biggest disadvantage of using JSP in JSF is that JSP writes to the response as soon as it encounters template text content, while JSF would like to do some pre/post processing with it. In JSF 1.0/1.1 the following JSF code
<h:outputText value="first"> second <h:outputText value="third"> fourth
would produce
second fourth first third
This was during the JSF 1.0/1.1 ages a headache. Developers would need to wrap template text like second
and fourth
in the above example in <f:verbatim>
tags over all place. JSF 1.2 has solved it with an improved view handler which parses the JSP instead of executing it, but it was under the hoods still very clumsy as JSP syntax isn't "well-formed" like XML. A XML based view technology was strongly desired, so that an efficient SAX based parser could be used. And Facelets was born (among Ken Paulsen's "JSFTemplating").
Also, unified EL #{}
couldn't be used in JSP template text, resulting in ugly —and for starters unintuitive— mixing of ${}
and #{}
. Also, JSTL could in JSF 1.x on JSP not be used as view build time tags. Also, JSP syntax with <% %>
things is old school and the possibility of embedding raw Java code in JSP is considered a very poor practice which breaks MVC ideology.
All with all, in JSF/MVC perspective, JSP is simply ugly and terrible and Facelets is simply clean and awesome.