• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing a for loop in EL expression  RSS feed

 
Sammy Bill
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I trying to avoid using scriptlet. i have a peace of code as follow



how can i change it to use EL?

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The EL is only used for evaluating expressions. To iterate over a collection you'd use the JSTL <c:forEach> action.
 
Sammy Bill
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:The EL is only used for evaluating expressions. To iterate over a collection you'd use the JSTL <c:forEach> action.


So you are saying I have to use scriptlet for such loop?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oussama M Billah wrote:So you are saying I have to use scriptlet for such loop?


Bear Bibeault wrote:To iterate over a collection you'd use the JSTL <c:forEach> action.


How could this be interpreted as "use scriptlets"?

Scriptlets are never necessary, and should no longer ever be used,
 
rmail kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello My Friend

just i give one example for loop using JSTL.

<c:forEach var="SecName" items="${pagename}" varStatus="slNo">



 
Sammy Bill
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Oussama M Billah wrote:So you are saying I have to use scriptlet for such loop?


Bear Bibeault wrote:To iterate over a collection you'd use the JSTL <c:forEach> action.


How could this be interpreted as "use scriptlets"?

Scriptlets are never necessary, and should no longer ever be used,


that's it what i m doing, NO scriptlet, and I dont want to use them. i was not thinking of changing a simple for loop into a loop that uses collections. so you are saying in my action class i should create a list of integer, then loop through that list using the <c:foreach> tag.
it makes sense now.

Thanks
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No collection is needed. Most of the time you WILL use a collection with the tag, but it is not necessary.
The <c:forEach> loop supports a syntax for just iterating over a set of numbers.


I would recommend you grab a hold of the JSTL Specification from this page.
It is very readable, and an excellent reference for the JSTL tags.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!