Jsf 在facelet中使用include时出现问题

Jsf 在facelet中使用include时出现问题,jsf,include,facelets,Jsf,Include,Facelets,我有包括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/

我有包括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>
但什么也没有显示。我只得到一张空白页,没有错误。使用
ui:composition
是否有错?我试过使用
ui:component
,但也没用


更新:根据我的Facelets Essentials指南,它说:

ui:include
标记可用于将另一个Facelets文件包含到您的 文件。它只包含您指定的任何源文件。你可以 包括任何具有
ui:component
ui:composition
标记的Facelets文件 (将内容修剪到外部)或只是 XHTML或XML


这是怎么回事?包含范围之外的内容是否被删除?如何在不修剪外部内容的情况下包含页面?

我通过删除
并直接在
中添加名称空间来解决此问题,如下所示:

<table class="adminform" xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a="http://richfaces.org/a4j">
<ui:define name="content">
    <ui:include src="/admin/admin_generic.xhtml" />
</ui:define>

现在我的页面看起来像这样:

<table class="adminform" xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a="http://richfaces.org/a4j">
<ui:define name="content">
    <ui:include src="/admin/admin_generic.xhtml" />
</ui:define>

必须放置在
中,其中
模板包含适当的
标记。您已将其移动到没有
模板的
。没有模板意味着没有内容

从技术上讲,要达到您的要求,您必须将
替换为

请注意,您必须在浏览器中打开
admin\u generic.xhtml
。如果您的目的是在浏览器中打开
somepage.xhtml
,那么
实际上必须留在
somepage.xhtml
中。但是,您可以用一个简单的
替换
的主体

<!DOCTYPE html>
<ui:composition 
    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="template.xhtml">

    <ui:define name="head">
        <title>Title</title>
    </ui:define>

    <ui:define name="header">
        <h1>Header</h1>
    </ui:define>

    <ui:define name="content">
        <ui:include src="admin_generic.xhtml" />
    </ui:define>
</ui:composition>

标题
标题
它允许
,因此您不必将
放在根目录下

<!DOCTYPE html>
<ui:composition 
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets">

    <table><tr><td>table</td></tr></table>
</ui:composition>

桌子

不客气。将来,尽量减少问题中不相关的干扰,以便其他人更快地回答:)您不必将表声明为root。一个
ui:composition
也同样有效。我认为你的误解是由许多试错造成的。关键是
ui:define
必须在
ui:composition
中使用
模板
<!DOCTYPE html>
<ui:composition 
    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="template.xhtml">

    <ui:define name="head">
        <title>Title</title>
    </ui:define>

    <ui:define name="header">
        <h1>Header</h1>
    </ui:define>

    <ui:define name="content">
        <ui:include src="admin_generic.xhtml" />
    </ui:define>
</ui:composition>
<!DOCTYPE html>
<ui:composition 
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets">

    <table><tr><td>table</td></tr></table>
</ui:composition>