This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes EL basic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "EL basic" Watch "EL basic" New topic
Author

EL basic

jibs parap
Ranch Hand

Joined: Dec 07, 2004
Posts: 134
HF says the 1st thing in expression is either an implicit object or attribute. But in the following program-let, listElement used inside {} is a variable declared for custom tags.

<c:forEach var='listElement' items="{movieList}">
${listElement}
</c:forEach>

How do you generalize this concept of accepting the custom tag variable?

Thanks
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

But that variable must be placed as an attribute of some scope for the EL to read it. Play around a with the code a little to see if you can determine which scope holds the variable. What scope would make the most sense? Was the result of your testing what you expected?


A good workman is known by his tools.
jibs parap
Ranch Hand

Joined: Dec 07, 2004
Posts: 134
I understand 'movieList' should be an attribute. And you are saying 'listElement' should be considered as an attribute because its one of the elements in movieList?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

Originally posted by jibs parap:
And you are saying 'listElement' should be considered as an attribute because its one of the elements in movieList?
No. It might be helpful for you to grab a copy of the JSTL Specification and see what it says about the operation of the <c:forEach> tag with regards to the creation of scoped variables (what you have been calling "attributes").


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

And don't forget to put the $ here : items="${movieList}"


[My Blog]
All roads lead to JavaRanch
jibs parap
Ranch Hand

Joined: Dec 07, 2004
Posts: 134
Thanks all; I nearly figured that out.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Originally posted by Bear Bibeault:
No. It might be helpful for you to grab a copy of the JSTL Specification and see what it says about the operation of the <c:forEach> tag with regards to the creation of scoped variables (what you have been calling "attributes").

In my book, scoped variable = attribute because any scoped (as in page, request, session, or application scope) variable is retrievable through a getAttribute method in the API.

The following jsp code (please forgive my scriptlets, Bear ) illustrates that the "var" from c:forEach does get saved as an attribute of some scope (aka scoped variable). I won't reveal which scope - our friend will need to try it out. That's the best way to learn.

 
Don't get me started about those stupid light bulbs.
 
subject: EL basic
 
Similar Threads
How to display data from an arraylist of more than one bean on jsp page using scripting or jsp tags?
Display text from MySQL Text Field
bean and for each
JSTL iteration of a list with numbering
Doubt in Attribute with JSTL.Thanks!