aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "c:forEach" Watch "c:forEach" New topic
Author

c:forEach

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 array.....now 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 scope....now 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 now...you 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 iteration....so "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
author
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:


Cheers,
Bryan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: c:forEach
 
Similar Threads
Display ArrayList of objects without jstl?
Pass non string object as attribute to Tag File
Iterating over Map using JSTL
help with custom tags
doubt in JSTL set tag