List Info

Thread: Nested c:forEach bug




Nested c:forEach bug
user name
2007-01-31 18:39:15

I seem to have found a bug in c:forEach when nested in another c:forEach. The inner for loop does not output correct values for JSTL expression after the second iteration. The values become empty

Snippet of my code

<c:forEach items="${workItems}" var="workItem" varStatus="item"&gt;

 &nbsp;  <c:forEach items="${workItem.workItemStatusList}" var="workItemStatus" varStatus="status">

 &nbsp; &nbsp; &nbsp;  <h:outputText id="status#{item.index}#{status.index}#{workItemStatus.id}" value="Description ${workItemStatus.status.description}" />

 &nbsp;  </c:forEach>

</c:forEach>

In the above, you expect the output to be

Description PENDING

Description RECORDED

Description REJECTED

etc

Instead you get

Description PENDING

Description

Description

Now if I change the loop to a nested ui:repeat I get the expected output.

<ui:repeat  value="${workItems}" var="workItem">

 &nbsp;  <ui:repeat value="${workItem.workItemStatusList}" var="workItemStatus" >

 &nbsp; &nbsp;   ; <h:outputText value="Descriptio ${workItemStatus.status.description}" />

 &nbsp;  </ui:repeat>

</ui:repeat>;

The reason why I am using a c:forEach is that it works nicely with h:panelGrid.&nbsp;A ui:repeat will mean that I have to use html tables which would muck up our neat layout code. Another limitation of ui:repeat is that there is no way to output an index. In this example I don't need it, in others I may.

Is this a known problem? Has anyone else come across it?

Mel


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )