Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL c:forEach tag and EL  RSS feed

 
Adrian Sosialuk
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

1. <c:forEach var="foo" items="${myList}">
2. ${foo} <br>
3. </c:forEach>

Could someone please explain me line 2 ? I thought that
you can only use an implicit object or an attribute as
an EL expression inside {} ...

Thanks,

Adrian.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use any scoped variable -- what you called an "attribute". The <c:forEach> tag creates such a variable as part of its processing named whatever you express in its var attribute. In this case, that's foo.
 
Adrian Sosialuk
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All right !

That makes sense now. By saying attribute I meant
an attrbute added to one of the scopes ...


Thanks a lot !

Adrian
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Adrian Sosialuk:
That makes sense now. By saying attribute I meant
an attrbute added to one of the scopes ...

Right. Because the term attribute is also used in the HTML/XML sense, the term 'scoped variable' has been coined to prevent ambiguity.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. Whenever you see the var and scope attributes on a JSTL tag, it's a good indication that the values will be used to create a scoped variable that can be referenced in the EL.
 
Adrian Sosialuk
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Right. Because the term attribute is also used in the HTML/XML sense, the term 'scoped variable' has been coined to prevent ambiguity.


That's a good point ;) I didn't think of that.

Thanks a lot for the tips !

Adrian
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!