Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I conditionally render an <f:facet>?

Tags:

I would like to be able to conditionally omit a footer from a PrimeFaces panel element:

<p:panel header="some text">
    <f:facet name="footer">
        #{message}
    </f:facet>
    <!-- ... -->
</p:panel>

I hoped that the rendered attribute would work:

<p:panel header="some text">
    <f:facet name="footer" rendered="#{!empty message}">
        #{message}
    </f:facet>
    <!-- ... -->
</p:panel>

But the footer is still rendered, with empty content. It appears that facet does not have the rendered attribute: http://www.jsftoolbox.com/documentation/help/12-TagReference/core/f_facet.html.

What's the right way to do this?

like image 292
Matt Ball Avatar asked Dec 06 '10 17:12

Matt Ball


1 Answers

I was able to solve this by swapping the facet out for an attribute. To summarize:

This works

<p:panel ...>
    <f:attribute name="footer" value="#{message}"/>
    <!-- ... -->
</p:panel>

But this doesn't work

<p:panel footer="#{message}">
    <!-- ... -->
</p:panel>

Neither does this

<p:panel ...>
    <f:facet name="footer">#{message}</f:facet>
    <!-- ... -->
</p:panel>

Nor this

<p:panel ...>
    <f:facet name="footer">
        <h:outputText value="#{message}" rendered="#{!empty message}"/>
    </f:facet>
    <!-- ... -->
</p:panel>

by "works" I mean:

"renders no footer — not just an empty footer — when #{message} is empty or null; otherwise, correctly renders the footer with the specified text."


PrimeFaces forum thread on this issue

like image 142
Matt Ball Avatar answered Oct 01 '22 23:10

Matt Ball