【问题标题】:How to create a reuseable template with header/footer/navigation?如何使用页眉/页脚/导航创建可重用模板?
【发布时间】:2012-04-01 15:20:09
【问题描述】:

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

【问题讨论】:

    标签: templates jsf jsf-2 facelets


    【解决方案1】:

    这听起来像是主模板的经典案例。在这样的模板中,您放置所有页面共有的所有内容,然后您的实际页面引用此模板并“填写空白”。在某种程度上,它与经典的包含相反。

    例如

    /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>
    

    【讨论】:

      猜你喜欢
      • 2014-09-29
      • 2011-08-25
      • 1970-01-01
      • 2016-08-28
      • 1970-01-01
      • 1970-01-01
      • 2011-12-24
      • 1970-01-01
      相关资源
      最近更新 更多