2 Replies Latest reply on Sep 23, 2008 12:24 PM by Trond Arve Nordheim

    CDK and <c:forEach /> compile error

    Trond Arve Nordheim Newbie

      Hi

      I'm using the RichFaces CDK to generate some JSF components in our application and I think I've discovered what looks like a bug in the template compiler that Maven uses to generate my component class.

      The problem, specifically, is <c:forEach /> iterations, which there seems to be compiler support for (/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ForEachTemplateElement.java), all though it seems to be some bugs there that cases compile errors.

      My template code is as follows:

      <c:forEach var="element" items="#{component.attributes['elements']}">
       test
      </c:forEach>
      


      Which should be a fairly simple loop. When the CDK tries to compile this using the ForEachTemplateElement, the following warnings are given;

      [WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = META-INF/templates/templatecompiler/FORElement_2.vm [line 2,column 40] : $from is not a valid reference.
      [WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = META-INF/templates/templatecompiler/FORElement_2.vm [line 3,column 103] : $to is not a valid reference.


      And then, when it tries to compile the actual Java file generated from the CDK, I get these errors:

      D:\Code\...\HorizontalImageMenu.java:[112,108] ';' expected
      D:\Code\...\HorizontalImageMenu.java:[112,109] illegal start of expression
      D:\Code\...\HorizontalImageMenu.java:[113,53] ';' expected


      The actual code generated in HorizontalImageMenu is:
      for (
       variables.setVariable("element", $from);
       Integer.getInteger(variables.getVariable("element").toString()).intValue() < Integer.getInteger($to).toString()).intValue();
       variables.addValueToVariable("element", new Integer(1) )
       ) {
      writer.writeText(convertToString("test"),null);
      
      }
      


      I've been looking through ForEachTemplateElement.java and the templates it uses, and it seems to be some weirdness there, especially with the getTemplate1Name() method returning "FORElement_2.vm" and the getTemplate2Name() method returning "FORElement_1.vm" - judging from the content of these templates it should be the other way around.

      Is this functionality currently bugged, or am I using it wrong?