在PrimeFaces菜单组件中混合使用静态和动态菜单项 [英] Mixing static and dynamic menu entries in PrimeFaces menu components
问题描述
我想在标记中将菜单的一部分保持静态,而在Java中动态地生成另一部分.
I'd like to keep a part of my menu static in markup, and have another part dynamically generated in Java.
<p:menubar>
<p:menuitem value="static stuff"/>
<p:submenu label="dynamic stuff" model="#{bean.dynamicMenu}"/>
<!-- more static stuff -->
</p:menubar>
这仅显示静态项目,并且从不调用我的getDynamicMenu
方法,因为p:submenu
不具有model
属性.
This shows only the static items and never calls my getDynamicMenu
method cause p:submenu
does not take a model
attribute.
我尝试在菜单结构中使用ui:include
将标记移动到一个额外的文件中,并在不同的上下文中包含该标记,但是Primefaces抱怨它不喜欢将其作为p:menubar
和/或p:submenu
的子元素
I tried using ui:include
within the menu structure to move the markup in an extra file and include that in different contexts, but Primefaces complained that it does not like that as child element of p:menubar
and / or p:submenu
.
如何在xhtml中将菜单的某些部分保持静态,而在Java中如何使菜单的某些部分保持动态?
How can I keep parts of my menu static in xhtml and parts dynamic in Java?
推荐答案
虽然我不能使用ui:include
,但是我可以使用c:forEach
,就像@Kukeltje在他的评论中指出的那样:
While I cannot use ui:include
, I can use c:forEach
, as @Kukeltje pointed out in his comment:
<p:submenu label="Dynamic 0" rendered="#{list.size() eq 0">
<p:menuitem value="Nothing here..." url="...">
</p:submenu>
<p:submenu label="Dynamic 1" rendered="#{list.size() eq 1}">
<c:set var="node" value="#{list[0]}"/>
<!-- more menu structure here -->
</p:submenu>
<p:submenu label="Dynamic N" rendered="#{list.size() gt 1}">
<c:forEach items="#{list}" var="item">
<p:submenu label="#{item}">
<!-- more menu structure here -->
</p:submenu>
</c:forEach>
</p:submenu>
这使我可以根据自己的后备bean来显示不同的菜单.
This allows me to present a different menu depending on my backing bean.
再次感谢,@ Kukeltje!
Thanks again, @Kukeltje!
这篇关于在PrimeFaces菜单组件中混合使用静态和动态菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!