2

I am trying to dynamically generate rich menu items inside a rich context menu component. Here is my code:

<ui:repeat var="group" value="#{myBean.groups}" >
  <div align="center"> 
    <rich:panel>
      <h:graphicImage value="#{group.iconUrl}"/>
      <rich:contextMenu attached="true">
        <c:forEach var="child" items="#{group.children}">
          <rich:menuItem label="#{child.name}" />
        </c:forEach>
      </rich:contextMenu>
    </rich:panel>   
  </div>
</ui:repeat>

I am using this tag library :

xmlns:c="http://java.sun.com/jsp/jstl/core

My problem is that the menu items aren't being generated. I have also tried replacing c:forEach with ui:repeat but it still won't work.


I tried a little experimentation to eliminate some factors. I removed rich context menu and used ui:repeat

<ui:repeat var="group" value="#{myBean.groups}" >
  <div align="center"> 
    <rich:panel>
      <h:graphicImage value="#{group.iconUrl}"/>
      <ui:repeat var="child" value="#{group.children}">
         <h:outputText value="#{child.name}" />
      </ui:repeat>
    </rich:panel>   
  </div>
</ui:repeat>

This code snippet above worked. I guess there is a conflict with the rendering of the context menu and the ui repeat.

Sadly, I really kind of need to place group.children in a rich context menu component. Can you suggest any approach that will help me achieve what I want?


NOTE: I am using servlet version 3.0

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
inxis
  • 51
  • 1
  • 4

1 Answers1

1

The <c:forEach> runs during view build time, when the XHTML file is to be transformed into a JSF component tree. The <ui:repeat> runs during view render time, when the JSF component tree is about to produce HTML.

So, in your particular example, at the moment the <c:forEach> runs, the #{group} variable as definied by <ui:repeat> is nowhere available in the EL scope and the <c:forEach> basically retrieves null as items value and hence has nothing to iterate over.

Your construct will only work if you replace the outer <ui:repeat> by <c:forEach> as well.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555