Search code examples
jsf-2richfacescontextmenuhtml

How can I add dynamic items to a context menu?


I am migrating my app to jsf2 and richfaces 4.3.1 and I have a problem with the component rich:contextMenu.

The context menu should has some final items (like the "All" one in the snippet) and others taken from a List attribute defined in a "bean".

With jsf1.2 and richfaces 3.3.x the "c:forEach" element worked fine but in the new configuration it doesn't. Any ideas?

The code snippet is like:

<rich:contextMenu id="menu" showEvent="click" target="panel" mode="ajax" >

    <rich:menuItem label="All" action="#{bean.search}" render="list">
        <a4j:param assignTo="#{bean.currentLabelId}" value="0" />
    </rich:menuItem>

    <c:forEach var="item" value="#{bean.labelSelectItemList}">

        <rich:menuItem label="#{item.label}" action="#{bean.search}" render="list">
            <a4j:param name="param1" assignTo="#{bean.currentLabelId}" value="#{item.value}" />
        </rich:menuItem>

    </c:forEach>

</rich:contextMenu>

Solution

  • Just summarizing the solution from comments:

    Replace http://java.sun.com/jstl/core namespace url occurances by http://java.sun.com/jsp/jstl/core (http://java.net/jira/browse/FACELETS-245)

    And also davidml comment:

    another wrong thing: the c:forEach needs an "items" atribute instead of "value"