4 Replies Latest reply on May 12, 2010 5:26 AM by Igor Grinfeld

    Nested <c:forEach> causes errors

    Igor Grinfeld Newbie

      I 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:



      <c:set var="hourIndex" value="1"/>

      <c:forEach var="trName" items="#{this:getHoursList( component )}">

           <c:set var="hourIndex" value="${hourIndex+1}"/>  


           <td class="hour" scope="row">#{trName}</td>

           <c:forEach var="dayIndex" items="#{this:getDayIndexes( component )}">














                                     (Integer)variables.getVariable( "dayIndex" ),

                                    (Integer)variables.getVariable( "hourIndex" )

                               ).getValue() );

















      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:


      <c:object var="daysCount" type="java.lang.Integer"

      <c:forEach var="dayIndex" begin="0" end="#{daysCount}" step="1">









      causes 'Cannot find symbol. symbol  : method getInteger(java.lang.Integer) location: class java.lang.Integer' error

      inspecting of generated renderer shows :



      for (

      variables.setVariable("dayIndex", "0");

      Integer.getInteger(variables.getVariable("dayIndex").toString()).intValue() < Integer.getInteger(daysCount).toString().intValue();

      variables.addValueToVariable("dayIndex", new Integer(1) )





      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?