Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用JSF2.0 Facelets在XHTML中包含另一个XHTML?_Jsf_Xhtml_Include_Jsf 2_Facelets - Fatal编程技术网

如何使用JSF2.0 Facelets在XHTML中包含另一个XHTML?

如何使用JSF2.0 Facelets在XHTML中包含另一个XHTML?,jsf,xhtml,include,jsf-2,facelets,Jsf,Xhtml,Include,Jsf 2,Facelets,在XHTML页面中包含另一个XHTML页面的最正确方法是什么?我一直在尝试不同的方法,但没有一种有效。包括页面: <!-- opening and closing tags of included page --> <ui:composition ...> </ui:composition> 包括第页: <!--the inclusion line in the including page with the content--> <ui:

在XHTML页面中包含另一个XHTML页面的最正确方法是什么?我一直在尝试不同的方法,但没有一种有效。

包括页面:

<!-- opening and closing tags of included page -->
<ui:composition ...>
</ui:composition>
包括第页:

<!--the inclusion line in the including page with the content-->
<ui:include src="yourFile.xhtml"/>
使用ui:composition启动包含的xhtml文件,如上所示。 您可以使用ui:include将该文件包括在includexhtml文件中,如上所示。 最基本的方法是。包含的内容必须放在内部

母版页/page.xhtml的启动示例:

这需要由/page.xhtml打开。请注意,您不需要在include文件中重复,否则会导致错误

可以在中使用动态EL表达式。另见

/ 一种更高级的包含方法是模板化。这基本上包括反过来。母版模板页面应用于声明插入已定义模板内容的位置。使用主模板页面的模板客户端页面应用于定义要插入的模板内容

母版模板页/WEB-INF/template.xhtml作为设计提示:页眉、菜单和页脚甚至可以是文件:

这需要由/page.xhtml打开。如果没有,则将显示内部的默认内容(如果有)

您可以将参数传递给或通过

在include/template文件中,它将以{foo}的形式提供。如果您需要传递许多参数,那么您最好考虑将包含文件注册为标记文件,以便最终可以像这样使用它。另见

您甚至可以通过传递整个bean、方法和参数。另见

设计提示 不应该仅仅通过输入/猜测URL就可以公开访问的文件需要放在/WEB-INF文件夹中,就像上面示例中的include文件和模板文件一样。另见

外部和外部不需要任何标记HTML代码。您可以放置任何内容,但它们将被Facelets忽略。在其中放置标记只对web设计师有用。另见

HTML5 doctype是目前推荐的doctype,尽管它是一个XHTML文件。您应该将XHTML视为一种允许您使用基于XML的工具生成HTML输出的语言。另见和

CSS/JS/image文件可以作为可动态重新定位/本地化/版本化的资源包含。另见

您可以将Facelets文件放入可重用的JAR文件中。另见


有关高级Facelets模板的真实示例,请查看和的src/main/webapp文件夹。

Hi Balus,关于:最基本的方法是。包含的内容必须放在内部。我认为包含的内容可以放在

中,它会起作用。@KorayTugay:是的,没错。ui:合成只需要a使用上面的模板,或者b包装所有内容,这样你就可以用浏览器或HTML编辑器加载文件。嗨,你能帮我解开这个谜吗?在过去的三天里,我一直在磕头@奥德修斯:如果它实际上是一个组合,则不会。如果仅在facelet中声明,那么您也必须像这样声明doctype,否则在使用HTML实体时会得到一个被引用但未声明的实体错误。有时,仅使用文件名时识别路径是不够的。对于那些尝试了上面的文件包含但没有成功的人。您可以尝试在文件名或/WEB-INF目录前添加斜杠符号。所以看起来像是
<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <h:head>
        <title>Include demo</title>
    </h:head>
    <h:body>
        <h1>Master page</h1>
        <p>Master page blah blah lorem ipsum</p>
        <ui:include src="/WEB-INF/include.xhtml" />
    </h:body>
</html>
<ui:composition 
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <h2>Include page</h2>
    <p>Include page blah blah lorem ipsum</p>
</ui:composition>
  
<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <h:head>
        <title><ui:insert name="title">Default title</ui:insert></title>
    </h:head>
    <h:body>
        <div id="header">Header</div>
        <div id="menu">Menu</div>
        <div id="content"><ui:insert name="content">Default content</ui:insert></div>
        <div id="footer">Footer</div>
    </h:body>
</html>
<ui:composition template="/WEB-INF/template.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

    <ui:define name="title">
        New page title here
    </ui:define>

    <ui:define name="content">
        <h1>New content here</h1>
        <p>Blah blah</p>
    </ui:define>
</ui:composition>
<ui:include ...>
    <ui:param name="foo" value="#{bean.foo}" />
</ui:include>
<ui:composition template="...">
    <ui:param name="foo" value="#{bean.foo}" />
    ...
</ui:composition >