0

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.

Community
  • 1
  • 1
Erik I
  • 972
  • 1
  • 11
  • 28

1 Answers1

2

The PrimeFaces p:menuButton, like many other components, including most menu components, supports the model attribute. This is mentioned on page 329 in the PF6 documentation. The 'Dynamic menus` section of this component refers to the 'common' dynamic menus section on page 323. There you can read how to do this.

And to prevent this answer to be a 'link only' (to external sites, here is the sort of duplicate of this question: Primefaces : how to create <p:menubar> dynamically in primefaces 4?

Community
  • 1
  • 1
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • I guess this is what we looked for. As we are trying to add this to every row in a table I guess we will try something along the lines of . Will try that now. Thanks a lot! – Erik I Nov 11 '16 at 14:03