本文介绍了为什么从 JSF2.0 开始,作为视图定义语言,Facelets 比 JSP 更受欢迎?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我看到从 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 .

推荐答案

没错,JSP 有一些 模板 能力,但在 JSF 中使用 JSP 的最大缺点是 JSP 一遇到模板文本内容就写入响应,而 JSF 想做一些预/用它进行后期处理.在 JSF 1.0/1.1 中,以下 JSF 代码

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

会产生

第二第四第一第三

这是在 JSF 1.0/1.1 时代 头痛.开发人员需要将上例中的 secondfourth 等模板文本包裹在 标签中.JSF 1.2 使用改进的视图处理程序解决了这个问题,该处理程序解析 JSP 而不是执行它,但它在底层仍然非常笨拙,因为 JSP 语法不像 XML 那样格式良好".强烈需要基于 XML 的视图技术,以便可以使用高效的基于 SAX 的解析器.Facelets 诞生了(在 Ken Paulsen 的JSFTemplating"中).

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 模板文本中使用,导致丑陋的—对于初学者不直观${}#{} 的混合.此外,JSTL 可以在 JSP 上的 JSF 1.x 中不被用作 查看构建时间标签.此外,带有 <% %> 东西的 JSP 语法是老派,在 JSP 中嵌入原始 Java 代码的可能性被认为是 非常糟糕的做法 打破了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 更受欢迎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:32