【发布时间】:2011-05-05 14:41:37
【问题描述】:
我遇到了包含 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。
这是怎么回事?包含之外的内容是否被修剪掉了?我怎样才能只包含页面,而不修剪外面的内容?
【问题讨论】: