• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

c:forEach

 
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
${item} or ${pageScope.item} is same.
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
We can walk to school together. And we can both read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic