This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

forEach tag

 
swapna hyderabad
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

<c:forEach var="i" items="${collection}" varstatus="counter">
.
.
</c:forEach>

<%=counter.count%>

wahat will be the out put?
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried it? Where does the question come from? It won't compile, just looking at it, but I'll leave you to figure out why...
 
swapna hyderabad
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Chares

I dd't tried....as of my knowledge also it wont compile
but i have seen in one mock exam it is telling that it will compile but nothing will print.That's waht i got confused/surprised then posted it.
 
Surajsingh Thakur
Ranch Hand
Posts: 124
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sapna...
I think when you call the varStatus variable that is counter after the completion of forEach,then <%=counter.count%> will print the default value of count which = 1
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have seen in one mock exam

Please quote your sources.
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Here counter goes out of scope after c:forEach. Just like a local variable declared in a for loop, In java it will show a compiler error where as in EL it is handled gracefully and the result is empty string.

From scope: About varStatusTag
Name of the exported scoped variable for the status of the iteration. Object exported is of type javax.servlet.jsp.jstl.core.LoopTagS tatus. This scoped variable has nested visibility.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here counter goes out of scope after c:forEach

The original code is using a scriptlet, not an EL expression.
 
Gunnar Maluf
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if the expression was inside the for tag it would not compile. Expressions doesnt have access to the tag vars.

correct me if im wrong.

regards
Gunnar
[ December 04, 2008: Message edited by: Gunnar Maluf ]
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gunnar Maluf:
Expressions doesnt have access to the tag vars.


correct
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic