Bug 40870 - Tag 'out' incorrectly handles variable 'param'
Summary: Tag 'out' incorrectly handles variable 'param'
Status: RESOLVED WONTFIX
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Standard Taglib (show other bugs)
Version: 1.1
Hardware: PC other
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-02 02:47 UTC by aklimuk
Modified: 2007-01-29 17:10 UTC (History)
0 users



Attachments
test.jsp (1008 bytes, text/html)
2006-11-02 02:50 UTC, aklimuk
Details

Note You need to log in before you can comment on or make changes to this bug.
Description aklimuk 2006-11-02 02:47:11 UTC
If loop variable is named 'param', tag 'out' evaluates it to EMPTY string.
If loop variable has any other name, it is processed correctly.

Example 1. Incorrect processing.
	<c:forEach items="${cols}" var="param">
		<c:out value="${param.name}"/><br>
	</c:forEach>

Example 2. Correct processing.
	<c:forEach items="${cols}" var="col">
		<c:out value="${col.name}"/><br>
	</c:forEach>

Example 3. Correct processing. This is modified Example 1.
	<c:forEach items="${cols}" var="param">
		<c:out value="${pageScope.param.name}"/><br>
	</c:forEach>

I checked the code in debugger. In all cases 'pageContext' contains attribute with correct name. E.g. in Example 1, 'pageContext' contains an attribute 'param' with correct value.

The same problem exists if <c:forEach> is replaced by <logic:iterate>.

Other tags work correctly in this case. E.g. following code works correctly:
	<c:forEach items="${cols}" var="param">
                <html:text name="param" property="name"/><br>
	</c:forEach>

So, the problem is somewhere inside 'out'.
Comment 1 aklimuk 2006-11-02 02:50:26 UTC
Created attachment 19069 [details]
test.jsp

For simplicity, this JSP contains definition of bean class used in the
described examples.
Comment 2 Henri Yandell 2006-11-06 12:22:31 UTC
Is this with the JSTL 1.1.2 release?

Looking at the source, I don't see the word 'param' mentioned, which is odd as
you'd expect either the Out of the ForEach code to mention 'param' somewhere for
this bug to be happening.
Comment 3 Rahul Akolkar 2006-11-06 12:31:37 UTC
'param' is an implicit JSP variable (map of HTTP request parameters), and IMO, 
its best to not step over implicit variables by re-defining them in any scope 
(choose a different variable name)
Comment 4 Henri Yandell 2006-11-06 17:16:21 UTC
Thanks Rahul - I'm very rusty :)
Comment 5 aklimuk 2006-11-08 01:31:00 UTC
(In reply to comment #3)
> 'param' is an implicit JSP variable (map of HTTP request parameters), and IMO, 
> its best to not step over implicit variables by re-defining them in any scope 
> (choose a different variable name)
> 

You are right, 'param' is am implicit EL variable. But despite this, tags 'forEach' and 'iterate' correctly create the loop variable 'param' and correctly place it to the page context. While looping, this variable is correctly changed. Besides, the tag 'html:text' correctly retrieves variable 'param' from the page context and correctly processes it.

So why these three tags correctly process 'param' variable, but 'out' doesn't?
This seems to be an inconsistency. Why some tags process 'param' in one way, some - in another way? Either NONE of tags should process 'param' as local variable, or ALL of them should process it in the same way.
Comment 6 Henri Yandell 2007-01-03 16:25:44 UTC
The loop isn't necessary, the following confirms the bug:

<c:set var="param" value="52"/>
<c:out value="${pageScope.param}"/><br/>
<c:out value="${param}"/><br/>
Comment 7 Henri Yandell 2007-01-03 16:40:00 UTC
Digging into it, my gut feel is that it's due to line 70 of
org/apache/taglibs/standard/lang/jstl/JSTLVariableResolver.java. It also
suggests that the same problem will exist for:

pageContext
pageScope
requestScope
sessionScope
applicationScope
param
paramValues
header
headerValues
initParam
cookie

Testing 'header', it's got the same problem.

I think it's not worth the time to try and rewrite this so that things can work
for some of them in certain contexts and not for other ones. 
So we should FAQ this and point out the pageScope workaround.
Comment 8 Henri Yandell 2007-01-29 17:10:26 UTC
Added to the FAQ:

http://wiki.apache.org/jakarta-taglibs/Standard1%2e1%2e3FAQ

Resoling WONTFIX.