问题描述
我已经读过好几次了:有些开发人员不主张在其XHTML文件中插入JSF/Facelets标签和HTML标签.显然,HTML标签不会成为UI组件树的一部分,但是这样做的缺点是什么?
I've read this several times now: some developers aren't advocates of interleaving JSF/Facelets tags with HTML tags in their XHTML files. Obviously the HTML tags won't be part of the UI component tree, but what's the disadvantage of that?
我经常找到一些代码示例,作者在其中进行这种混合:
I often find code examples where the authors do that kind of mixing:
http://www.ibm.com/developerworks/java/library/j-facelets/
http://www.packtpub.com/article/facelets-components-in-jsf -1.2
http://oreilly.com/catalog/9780596529246
"Seam in Action"还插入了JSF/Facelets和HTML标记.
"Seam in Action" also interleaves JSF/Facelets and HTML tags.
我对实际使用的内容感到困惑.我开始混用标签,但我开始相信这可能不是正确的选择.但是,我看不出为什么纯粹的方法更可取.
I'm confused about what to actually use. I started out mixing tags, but I'm beginning to believe it was probably not the right choice. However, I fail to see why the puristic approach is preferrable.
我肯定知道我有一个表,其中的JSF数据表没有给我足够的灵活性来显示我需要的内容,因此不可能纯粹地做到这一点.
I know for certain that I have a table where the JSF datatable doesn't give me enough flexibility to display what I need to, so doing it puristically isn't possible.
此外,我想知道为什么上面的示例都不使用f:view等代替硬编码的html,head,body等标记.
Furthermore I'm wondering why none of the examples above use f:view etc. instead of the hardcoded html, head, body etc. tags.
有人可以帮我清理一下吗?
Can anyone please clear this up for me?
推荐答案
在JSF 1.0/1.1时代,这确实不是一个好主意",因为在使用时,并非所有HTML都自动包含在JSF组件树中. JSP作为视图技术. JSF渴望在 JSF组件树之前呈现所有纯HTML.例如
During the JSF 1.0/1.1 ages this was indeed "not a good idea", because all the HTML was not automatically taken in the JSF component tree when using JSP as view technology. All plain HTML was eagerly by JSP rendered before the JSF component tree. E.g.
<p>Lorem ipsum <h:outputText value="#{bean.value1}"> dolor sit amet<p>
<p>Consectetur adipiscing <h:inputText value="#{bean.value2}" /> elit</p>
呈现为
<p>Lorem ipsum dolor sit amet<p>
<p>Consectetur adipiscing elit</p>
value1
<input type="text" value="value2" />
要解决此问题,您需要引入<f:verbatim>
.
To fix this you would need to bring <f:verbatim>
in.
<f:verbatim><p>Lorem ipsum </f:verbatim><h:outputText value="#{bean.value1}"><f:verbatim> dolor sit amet<p></f:verbatim>
<f:verbatim><p>Consectetur adipiscing </f:verbatim><h:inputText value="#{bean.value2}" /><f:verbatim> elit</p></f:verbatim>
这是真正的维护难题.这就是为什么如此讨厌JSF 1.0/1.1的主要原因之一.
This was a real maintenance pain. This was one of the major reasons why JSF 1.0/1.1 was so hated.
自从JSF 1.2起,有了新的视图处理程序,就不再需要<f:verbatim>
了.开发人员现在可以放心了.而且,新的视图处理程序允许JSF使用与JSP不同的视图技术,因此Facelets诞生了.
Since JSF 1.2, with the new view handler, the <f:verbatim>
was not necessary anymore. Developers can now breathe relieved. Moreover, the new view handler allowed JSF to use a different view technology than JSP and this way Facelets was born.
- Java的主要缺点是什么Server Faces 2.0?
- 是否可以将JSF + Facelets与HTML 4/5?
- JavaServer Faces 2.2和HTML5支持,为什么仍使用XHTML
- What are the main disadvantages of Java Server Faces 2.0?
- Why Facelets is preferred over JSP as the view definition language from JSF2.0 onwards?
- Is it possible to use JSF+Facelets with HTML 4/5?
- JavaServer Faces 2.2 and HTML5 support, why is XHTML still being used
这篇关于JSF/Facelets:为什么将JSF/Facelets与HTML标记混合不是一个好主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!