在 Facelets 中使用 include 时出现问题
我遇到问题,包括 Facelet 模板。我想拆分一些内容,以便我可以在其他地方重复使用它。
所以我改变了这段代码:
<!DOCTYPE html>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/layout/template.xhtml">
<ui:define name="head">
<title>Title</title>
</ui:define>
<ui:define name="header">
<h3>Header</h3>
</ui:define>
<ui:define name="content">
<table><tr><td>table</td></tr></table>
</ui:define>
</ui:composition>
改为:
<!DOCTYPE html>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/layout/template.xhtml">
<ui:define name="head">
<title>Title</title>
</ui:define>
<ui:include src="/admin/admin_generic.xhtml"/>
</ui:composition>
在 admin-generic.xhtml
中,我将代码包装在 ui:composition 中。
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:define name="header">
<h3>Header</h3>
</ui:define>
<ui:define name="content">
<table><tr><td>table</td></tr></table>
</ui:define>
</ui:composition>
但没有显示任何内容。我只是得到一个空白页,没有错误。使用 ui:composition
是否错误?我尝试过使用 ui:component
但这也没有帮助。
更新:根据我的 Facelets Essentials Guide,它说:
ui:include
标签可用于将另一个 Facelets 文件包含到您的 文档。它仅包含您指定的任何源文件。你可以 包含任何具有ui:component
或ui:composition
标记的 Facelets 文件 (修剪自身之外的内容)或只是一个片段 XHTML 或 XML。
是这样的吗?包含之外的内容是否被删除?如何只包含页面而不修剪外部内容?
I have problems including a facelet template. I wanted to split some content up, so that I can reuse it somewhere else.
So I changed this code:
<!DOCTYPE html>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/layout/template.xhtml">
<ui:define name="head">
<title>Title</title>
</ui:define>
<ui:define name="header">
<h3>Header</h3>
</ui:define>
<ui:define name="content">
<table><tr><td>table</td></tr></table>
</ui:define>
</ui:composition>
To this:
<!DOCTYPE html>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/layout/template.xhtml">
<ui:define name="head">
<title>Title</title>
</ui:define>
<ui:include src="/admin/admin_generic.xhtml"/>
</ui:composition>
And inside admin-generic.xhtml
I wrapped the code in a ui:composition.
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:define name="header">
<h3>Header</h3>
</ui:define>
<ui:define name="content">
<table><tr><td>table</td></tr></table>
</ui:define>
</ui:composition>
But nothing is shown. I just get a blank page, with no errors. Is it wrong using ui:composition
? I have tried with ui:component
but that didn't help either.
Update: According to my Facelets Essentials Guide, it says:
The
ui:include
tag can be used to include another Facelets file into your
document. It simply includes whatever source file you specify. You can
include any Facelets file that hasui:component
orui:composition
tags
(which trim the content outside themselves) or simply a fragment of
XHTML or XML.
Is that what is going on? Is the content outside of the include trimmed away? How can I just include the page, without the content outside being trimmed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
必须放置在
或
with 中template 包含适当的
标签。您已将其移至
但没有模板
。没有模板就意味着没有内容。从技术上讲,要实现您的要求,您必须将
替换为
。并将上面的页面(我假设它为
somepage.xhtml
)声明为admin_generic.xhtml
中的template
。请注意,您必须在浏览器中打开
admin_generic.xhtml
。如果您的目的是在浏览器中打开somepage.xhtml
,则
确实必须保留在somepage.xhtml
中。不过,您可以用简单的
替换
的主体。它允许
,因此您不一定需要将置于根目录。
The
<ui:define>
has to be placed in an<ui:composition>
or<ui:decorate>
with atemplate
containing the appropriate<ui:insert>
tags. You've moved it to an<ui:composition>
without atemplate
. No template means no content.Technically, to achieve your requirement, you have to replace the
<ui:include>
by<ui:insert>
.And declare the above page (I assume it as
somepage.xhtml
) astemplate
inadmin_generic.xhtml
.Note that you have to open
admin_generic.xhtml
in the browser instead. If your intent is to opensomepage.xhtml
in browser, then the<ui:define>
really has to stay insomepage.xhtml
. You can however replace the body of<ui:define>
by a simple<ui:include>
.It allows for
<ui:composition>
, so you don't necessarily need to put the<table>
to root.我通过删除
和
并直接在< 中添加命名空间来解决此问题/code> 像这样:
所以现在我的页面看起来像这样:
I solved this by removing the
<ui:composition>
and the<ui:define>
and just adding the namespace directly in the<table>
like this:So now my page looks like this: