且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么从JSF2.0开始,Facelets比JSP更适合作为视图定义语言?

更新时间:2023-12-04 17:13:53

确实,JSP具有 some

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

会产生

第二个第四个第三个

second fourth first third

这是在JSF 1.0/1.1时代的

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").

此外,统一的EL #{}不能在JSP模板文本中使用,从而导致丑陋的表情-对于初学者来说视图建立时间标签.此外,带有<% %>事物的JSP语法已经过时了,将原始Java代码嵌入JSP的可能性被认为是 MVC意识形态.

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.

总而言之,从JSF/MVC的角度来看,JSP只是丑陋而可怕,而Facelets却干净整洁.

All with all, in JSF/MVC perspective, JSP is simply ugly and terrible and Facelets is simply clean and awesome.