Search code examples
templatesjsffacelets

Hide specific parts of a template depending on template client


I have a header, body and footer defined in a Facelet template. I would like to hide the header and footer in my login page. How can I achieve that?


Solution

  • One of the ways would be to just render them conditionally based on the 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>
    

    Another way would be to parameterize it using <ui:param>:

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

    And then in the template client of /login.xhtml:

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