Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/6.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
Templates 如何创建具有页眉/页脚/导航的可重用模板?_Templates_Jsf_Jsf 2_Facelets - Fatal编程技术网

Templates 如何创建具有页眉/页脚/导航的可重用模板?

Templates 如何创建具有页眉/页脚/导航的可重用模板?,templates,jsf,jsf-2,facelets,Templates,Jsf,Jsf 2,Facelets,我一直在玩JSF,有一个项目正在工作,它有一个页眉/页脚/导航/内容 面板。然而,该项目从第1页转到第2页,以此类推,每一页都有不同的布局。如何创建一个可重复使用的模板,使页面之间保持相同的外观和感觉,即页眉/页脚/导航保持不变,但内容会更新?这听起来像是主模板的经典案例。在这样一个模板中,你把所有页面的公共内容都放进去,然后你的实际页面引用这个模板并“填空”。在某种程度上,它与经典的include相反 例如 /WEB-INF/templates/masterTemplate.xhtml: &l

我一直在玩JSF,有一个项目正在工作,它有一个页眉/页脚/导航/内容
面板。然而,该项目从第1页转到第2页,以此类推,每一页都有不同的布局。如何创建一个可重复使用的模板,使页面之间保持相同的外观和感觉,即页眉/页脚/导航保持不变,但内容会更新?

这听起来像是主模板的经典案例。在这样一个模板中,你把所有页面的公共内容都放进去,然后你的实际页面引用这个模板并“填空”。在某种程度上,它与经典的include相反

例如

/WEB-INF/templates/masterTemplate.xhtml:

<!DOCTYPE html>
<html lang="en"
    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" 
>
    <h:head>
        <title>
            <ui:insert name="title">Some title</ui:insert>
        </title>        
    </h:head>

    <ui:include src="header.xhtml"/>

    <h:body>
        <ui:insert name="content" />
    </h:body>

    <ui:include src="footer.xhtml"/>

</html>

一些头衔
页面使用此选项如下,例如:

/hello.xhtml

<ui:composition template="/WEB-INF/templates/masterTemplate.xhtml"
    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="title">hello</ui:define>

    <ui:define name="content">
        Hi, this is the page
    </ui:define>
</ui:composition>

你好
嗨,这是页面