为什么从JSF2.0开始,Facelets比JSP更适合作为视图定义语言? [英] Why Facelets is preferred over JSP as the view definition language from JSF2.0 onwards?
问题描述
我看到,从JSF2.0开始,Facelets视图定义语言是首选的视图定义语言,而不是JSP,后者已被弃用,因为它是一种传统的回退版本.我想了解为什么从JSF2.0起,Facelets比JSP更适合作为视图定义语言?我知道JSP也具有一些模板行为,这是采用Facelets的主要动力.
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 .
PS:我在Stackoverflow上浏览过这篇文章,但我不认为它回答了我的问题.因此,将其作为一个单独的问题发布.
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
会产生
第二个第四个第三个
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").
此外,统一的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.
这篇关于为什么从JSF2.0开始,Facelets比JSP更适合作为视图定义语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!