Uploaded image for project: 'Commons Jelly'
  1. Commons Jelly
  2. JELLY-283

Code block inside a ForEach loop should own its own variable scope(context)

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.0
    • Fix Version/s: None
    • Component/s: core / taglib.core
    • Labels:
      None

      Description

      Inside a ForEach loop, because jelly does not create a new JellyContext for a forEach loop. Any new variable declared inside this forEach loop will be populate to the current context.

      For example:

      <j:set var="test" value="a">
      <j:forEach begin="0" end="1">
      <!-- overwrite 'test' -->
      <j:set var="test" value="b">
      </j:forEach>

      <!-- now, the value of variable test is 'b' -->

      Ideally, forEach loop should have its own variable scope. Any new variable defined in this scope should not be populated to outer code block.
      People can avoid this problem by choosing variable names carefully.

      However, they are few tags are suffering from this issue. For example, the <http:parameter> uses a List to keep all the parameters. If you
      have a code looks like this:

      <j:forEach begin="0" end="2" indexVar="idx">
      <http:post url="http://google.com/search">
      <http:parameter name="q" value="${idx}" />
      </http:post>
      </j:forEach>

      It is going to send the following three requests to google

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              yunglin Yung-Lin Ho
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: