Nested <c:forEach> causes errors
igorg May 5, 2010 4:14 AMI try to create sample component representing weekly calendar with CDK version 3.3.3.Final. Most of the things waorks fine, but there are some problems in generated code.
First case:
{code:xml}
<c:set var="hourIndex" value="1"/>
<c:forEach var="trName" items="#{this:getHoursList( component )}">
<c:set var="hourIndex" value="${hourIndex+1}"/>
<tr>
<td class="hour" scope="row">#{trName}</td>
<c:forEach var="dayIndex" items="#{this:getDayIndexes( component )}">
<td>
<jsp:scriptlet><![CDATA[
variables.setVariable(
"slotVal",
component.getDataModel().getItemFromSlot(
(Integer)variables.getVariable( "dayIndex" ),
(Integer)variables.getVariable( "hourIndex" )
).getValue() );
]]></jsp:scriptlet>
${slotVal}
</td>
</c:forEach>
</tr>
....
{code}
The code above is from jspx template and it failes with 'iter is already defined in doEncodeBegin(....' error message. I checked generated renderer class and saw that two nested 'for( Iterator iter....' lines are generated by CDK plugin. Is it the bug or I've done something wrong?
Second case:
I tried to change code to escape two iterators declarations and changed:
{code:xml}
<c:forEach var="dayIndex" begin="0" end="#{daysCount}" step="1">
....
</c:forEach>
{code}
causes 'Cannot find symbol. symbol : method getInteger(java.lang.Integer) location: class java.lang.Integer' error
inspecting of generated renderer shows :
{code}
for (
variables.setVariable("dayIndex", "0");
Integer.getInteger(variables.getVariable("dayIndex").toString()).intValue() < Integer.getInteger(daysCount).toString().intValue();
variables.addValueToVariable("dayIndex", new Integer(1) )
)
...
{code}
It is clear that the error occured beacuse daysCount is Integer, but changing its type to String causes error in c:object.
Now I've replaced forEach tags with java scriplets and it works, but the idea of template is to use tags rather then java scriplets.
Can anybody show me right usage of nested forEach tags with CDK, please?