1

I'm building a template using jsf tags that has an optional sidebar. To render the html for the sidebar, I need to check if it's content is actually defined. More specifically, I'm trying to do this: (element classes are from bootstrap)

<div class="row">
    <div class="#{ check_if_has_sidebar ? 'col-md-9' : 'col-md-12' }">
        page content
    </div>
    <div class="col-md-3" jsf:rendered="#{check_if_has_sidebar}">
        <ui:insert name="sidebar-content" />
    </div>
</div>

How can I check if the page using this template defines content for "sidebar-content" using ui:define?

The following solution (suggested in a similar thread) doesn't work because I need to check BEFORE the definition of the param 'noSideBar':

<div class="row">
    <div class="#{ noSideBar ? 'col-md-9' : 'col-md-12' }">
        page content
    </div>
    <div class="col-md-3" jsf:rendered="#{not noSideBar}">
        <ui:insert name="sidebar-content">
            <ui:param name="noSideBar" value="true" />
        </ui:insert>
    </div>
</div>
Community
  • 1
  • 1
Luciano
  • 53
  • 6
  • Did it really not work during runtime? Or was that just your own untested assumption? – BalusC Jan 18 '16 at 13:28
  • It not work, I tested. The div for page contents uses the class 'col-md-9' independently if the sidebar is defined or not by the template client. Also, the div with the sidebar content (the one with the jsf:rendered parameter) is always rendered. If I invert the order of the divs, the class applied is correct, but the div for the sidebar is still rendered even though no sidebar is defined. Since I need a right sidebar, I cannot invert the order in my code. – Luciano Jan 18 '16 at 13:46
  • I know, but technical expectation is that ui:param is executed during view build time not during view render time. So code must just work. Which JSF impl/version are you using? In meanwhile, work around is to use `` instead of that ``. – BalusC Jan 18 '16 at 13:52
  • I'm using Mojarra 2.2.7. It worked with . Thanks! – Luciano Jan 18 '16 at 14:20
  • Is there really no way of testing if `` is set without checking ``? The importance is to automatically render decoration in the template only when there is something to render for the ``. – YoYo Oct 08 '18 at 03:38

0 Answers0