I have a p:menuButton in a p:column in a p:dataTable.
So far everything works fine.
Now I want to make the menuButton dynamic. However c:foreach is evaluated before rendering the table and primefaces doesn't like to use ui:repeat inside the p:menuButton.
How can I create a number of p:menuitem dynamically based on a collection on the row item I am looping over, i.e. what should I do instead of ?:someKindOfLoop in the example below?
<p:dataTable value='#{something.collection}' var='item'>
...
<p:column>
...
<p:menuButton value="Actions">
<p:menuitem value="View ..."
...>
<f:param name="something" value="#{item.id}"/>
</p:menuitem>
<?:someKindOfLoop x="#{item.subCollection}" y="var">
<p:menuitem value="View sub list "
...>
<f:param name="#{var.name}" value="#{var.id}"/>
</p:menuitem>
</?:someKindOfLoop>
</p:menuButton>
...
</p:column>
</p:dataTable>
Googling yields a number of similar cases, however I haven't found one yet that wasn't either about dynamically creating columns (like this: Why can <c:forEach> or <ui:repeat> not access <p:dataTable var>? ) or that doesn't deal with primefaces.
<c:forEach
runs early enough to create new control items like<p:anyControl
. After that, it's not permittet to change the count of control items in a page. It's possible if you use<c:forEach
with runtime values, but you will get some strange results. Because your data source is a<p:...
control item, there is no way to build some more. If there is a limit of possibilities, you may build always max. possible items with<c:forEach varStatus="var"
and insert arendered="#{bean.rendertest(var.index)
. Not nice but possible... – Holger