Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

jsf - Why Facelets is preferred over JSP as the view definition language from JSF2.0 onwards?

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 .

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...