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