使用 ui:include 时避免使用多个 DOCTYPE 和 html 标签
我们在“主”页面中使用了多个 ui:include
标签。要包含的页面如下所示:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=".." xmlns:ui="..." ...>
<ui:fragment rendered="${foo}">
some html code
</ui:fragement>
<ui:fragment rendered="${!foo || bar}">
some more html code
</ui:fragement>
</html>
使用 ui:include
进行模板化会导致多次重复 DOCTYPE
和 html
标记源代码,非常丑陋。 (当然,用户看不到,但我喜欢整洁的 html)
但是,如果我从未来的代码中删除 DOCTYPE
和 html
标签, included-xhtml 时,Faces Servlet 会引发异常,指出 ui:fragment
的前缀 ui
未绑定。
有谁知道,我如何在没有多个DOCTYPE
和html
的情况下包含另一个XHTML页面?
we are using several ui:include
tags in the "main" page. The page that is to be included looks like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=".." xmlns:ui="..." ...>
<ui:fragment rendered="${foo}">
some html code
</ui:fragement>
<ui:fragment rendered="${!foo || bar}">
some more html code
</ui:fragement>
</html>
Using the ui:include
for templating results in repeating the DOCTYPE
and html
tag several times in the source code, which is pretty ugly. (Sure, the user doesn't see, but I'm a fan of tidy html)
However, if I remove the DOCTYPE
and html
tag from the to-be-included-xhtml, the Faces Servlet throws an exception stating that the prefix ui
for ui:fragment
is not bound.
Does anybody know, how I can include another XHTML page without the multiple DOCTYPE
s and html
s?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该查看 ui:composition 标签。
我们还使用 ui:include 来包含 jsf2 页面,并解决您遇到的问题,我相信您可以通过添加 ui:composition 标签来更改包含的页面,如下所示:
You should take a look at the ui:composition tag.
We also use ui:include to include jsf2 pages, and to solve the problem you have I believe you could alter your included page by adding the ui:composition tag as follows: