我如何有条件地渲染一个 <f:facet>? [英] How do I conditionally render an <f:facet>?
问题描述
我希望能够有条件地从 PrimeFaces 面板元素中省略页脚:
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>
我希望 rendered
属性会起作用:
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>
但页脚仍然呈现,内容为空.facet
似乎没有 rendered
属性:http://www.jsftoolbox.com/documentation/help/12-TagReference/core/f_facet.html.
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.
这样做的正确方法是什么?
推荐答案
我能够通过将 facet
换成 attribute
来解决这个问题.总结一下:
I was able to solve this by swapping the facet
out for an attribute
. To summarize:
<p:panel ...>
<f:attribute name="footer" value="#{message}"/>
<!-- ... -->
</p:panel>
但这不起作用
<p:panel footer="#{message}">
<!-- ... -->
</p:panel>
这也没有
<p:panel ...>
<f:facet name="footer">#{message}</f:facet>
<!-- ... -->
</p:panel>
也不是这个
<p:panel ...>
<f:facet name="footer">
<h:outputText value="#{message}" rendered="#{!empty message}"/>
</f:facet>
<!-- ... -->
</p:panel>
<小时>
我所说的作品"是指:
"渲染 no 页脚 — 不只是空页脚 — 当 #{message}
为空或 null
时;否则,正确使用指定的文本呈现页脚."
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."
这篇关于我如何有条件地渲染一个 <f:facet>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!