How do I conditionally render an ?

前端 未结 12 2090
刺人心
刺人心 2020-12-28 16:55

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


    

        
相关标签:
12条回答
  • 2020-12-28 17:30

    Why don't you enclose the content of the footer into a panelGroup which has the rendered attribute?

    This way:

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

    I do it in my weapp and it works, no footer is rendered.

    I don't use primefaces though, I do it with h:datatable, but I think that it must works with p:panel too.

    0 讨论(0)
  • 2020-12-28 17:31

    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

    0 讨论(0)
  • 2020-12-28 17:31

    Not sure how well this would work for your footer, but I had the same issue with a legend I was trying to conditionally render. I fixed it by using the rendered on anything inside the facet tag.

    <p:fieldset>
    <f:facet name="legend">
        <h:outputText value="#{header1}" rendered="#{header1.exists}"/>
        <h:outputText value="#{header2}" rendered="#{not header1.exists}"/>
    </f:facet>
    content
    </p:fieldset>
    

    I had difficulty trying c:if with my ui:repeat, so this was my solution. Not quite the same as your problem, but similar.

    0 讨论(0)
  • 2020-12-28 17:33

    I successfully solved this problem using ui:fragment

    <ui:fragment rendered="...Test...">
    <f:facet name="footer">
    ...
    </f:facet>
    </ui:fragment>
    

    works for example to conditionnaly render the footer of a primefaces datatable (the rendered attribute of the facet does not work).

    0 讨论(0)
  • 2020-12-28 17:34

    For those who landed here trying to hide the footer, instead of header, but the syntax component.facets.footer didn't work, should try this:

    <p:panel id="panelContent">
        <c:if test="#{not empty cc.facets.footer}">
            <f:facet name="footer" height="100%">
               your content
            </f:facet>
        </c:if>
    </panel>
    
    0 讨论(0)
  • 2020-12-28 17:38

    Try with this, from primefaces web page

    <p:columnGroup type="footer">
        <p:row>
            <p:column colspan="3" style="text-align:right" footerText="Totals:" />
            <p:column footerText="your value in ajax" />
    
            <p:column footerText="your value in ajax" />
        </p:row>
    </p:columnGroup>
    

    clik here, to view primefaces' webpage

    0 讨论(0)
提交回复
热议问题