Arj*_*jms 23
这听起来像是主模板的经典案例.在这样的模板中,您可以将所有页面的所有内容放在一起,然后您的实际页面会引用此模板并"填写空白".在某种程度上,它也是经典的反面.
例如
/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>