You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Yung-Lin Ho (JIRA)" <co...@jakarta.apache.org> on 2007/11/17 00:26:43 UTC
[jira] Created: (JELLY-283) Code block inside a ForEach loop should
own its own variable scope(content)
Code block inside a ForEach loop should own its own variable scope(content)
---------------------------------------------------------------------------
Key: JELLY-283
URL: https://issues.apache.org/jira/browse/JELLY-283
Project: Commons Jelly
Issue Type: Bug
Components: core / taglib.core
Affects Versions: 1.0
Reporter: Yung-Lin Ho
Inside a ForEach loop, because jelly does not create a new JellyContent for a forEach loop. Any new variable declared inside this forEach loop will be populate to the current content.
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
- http://google.com/search?q=0
- http://google.com/search?q=0&q=1
- http://google.com/search?q=0&q=1&q=2
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (JELLY-283) Code block inside a ForEach loop should
own its own variable scope(context)
Posted by "Yung-Lin Ho (JIRA)" <co...@jakarta.apache.org>.
[ https://issues.apache.org/jira/browse/JELLY-283?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Yung-Lin Ho updated JELLY-283:
------------------------------
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
- http://google.com/search?q=0
- http://google.com/search?q=0&q=1
- http://google.com/search?q=0&q=1&q=2
was:
Inside a ForEach loop, because jelly does not create a new JellyContent for a forEach loop. Any new variable declared inside this forEach loop will be populate to the current content.
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
- http://google.com/search?q=0
- http://google.com/search?q=0&q=1
- http://google.com/search?q=0&q=1&q=2
Summary: Code block inside a ForEach loop should own its own variable scope(context) (was: Code block inside a ForEach loop should own its own variable scope(content))
> Code block inside a ForEach loop should own its own variable scope(context)
> ---------------------------------------------------------------------------
>
> Key: JELLY-283
> URL: https://issues.apache.org/jira/browse/JELLY-283
> Project: Commons Jelly
> Issue Type: Bug
> Components: core / taglib.core
> Affects Versions: 1.0
> Reporter: Yung-Lin Ho
>
> 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
> - http://google.com/search?q=0
> - http://google.com/search?q=0&q=1
> - http://google.com/search?q=0&q=1&q=2
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.