File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes c:forEach Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "c:forEach" Watch "c:forEach" New topic


Sayak Banerjee
Ranch Hand

Joined: Nov 28, 2006
Posts: 292
Hi guyz....could anyone figure this out?

Consider the following code snippet:-

We're doin' nothin' special here but looping over the attribute array and displayin' the each string in the as far as my knowledge goes(thanks to HFSJ) the first thing in an EL expression has to be an attribute or an EL implicit object...therefore ${array} makes sense....but what about ${item}....its just a variable(neither an attribute in any of the 4 scopes nor an EL implicit object)....The HFSJ book (page 440) says it is bound to tag is that a new scope altogether? What's the deal here? Could someone please explain.

Turn on, tune in, drop out.
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
${item} or ${pageScope.item} is same.
Sayak Banerjee
Ranch Hand

Joined: Nov 28, 2006
Posts: 292
I see....I figured it out can check this too...when you run the loop, for each iteration, "item" is bound to page scope and removed at the end of the "item" is basically a temporary page-scoped attribute for each iteration....therefore inside the loop body ${item} and ${pageScope.item} is the same...

Hey...Thanks man...that was a nice bit of information...definitely not on the book
Bryan Basham
Ranch Hand

Joined: Apr 30, 2001
Posts: 199
Hello Sayak,

I feel that I have to defend the HFSJ book. On page 440, we say in the Watch It! "That's right, tag scope. No this isn't a full-fledged scoped..."

I guess that we should have not made-up a name, but the concept is useful. Many custom tags (and JSTL tags) will create temporary attributes, usually in the page scope, but could also be in the request scope. These will only exist for the duration of the tag as you have accurately surmised. Think of this in the same way that you would think of the "scope" of a for-loop variable:

I agree. Here's the link:
subject: c:forEach
jQuery in Action, 3rd edition