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

c:forEach

 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${item} or ${pageScope.item} is same.
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic