【问题标题】:Hide specific parts of a template depending on template client根据模板客户端隐藏模板的特定部分
【发布时间】:2013-03-18 00:37:36
【问题描述】:

我在 Facelet 模板中定义了页眉、正文和页脚。我想在我的登录页面中隐藏页眉和页脚。我怎样才能做到这一点?

【问题讨论】:

    标签: templates jsf facelets


    【解决方案1】:

    其中一种方法是根据current view ID 有条件地渲染它们。

    <h:panelGroup id="header" layout="block" rendered="#{view.viewId != '/login.xhtml'}">
        Header.
    </h:panelGroup>
    
    <div id="body">
        <ui:insert name="body">Body.</ui:insert>
    </div>
    
    <h:panelGroup id="footer" layout="block" rendered="#{view.viewId != '/login.xhtml'}">
        Footer.
    </h:panelGroup>
    

    另一种方法是使用&lt;ui:param&gt; 对其进行参数化:

    <h:panelGroup id="header" layout="block" rendered="#{not hideHeaderAndFooter}">
        Header.
    </h:panelGroup>
    
    <div id="body">
        <ui:insert name="body">Body.</ui:insert>
    </div>
    
    <h:panelGroup id="footer" layout="block" rendered="#{not hideHeaderAndFooter}">
        Footer.
    </h:panelGroup>
    

    然后在/login.xhtml的模板客户端中:

    <ui:composition template="/WEB-INF/templates/layout.xhtml" ...>
        <ui:param name="hideHeaderAndFooter" value="true" />
        <ui:define name="body">
            ...
        </ui:define>
    </ui:composition>
    

    【讨论】:

    猜你喜欢
    • 2014-09-16
    • 2017-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-11
    • 2011-08-02
    相关资源
    最近更新 更多