• Post Reply Bookmark Topic Watch Topic
  • New Topic

forEach var  RSS feed

 
John Ip
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I would like to ask is there any way to reference the var of a forEach tag within a scriptlet? I would like to do some maunipulation to the var in a scriptlet.

<c:forEach var="item" items="items">

<% item.decrypt() %>

</c:forEach>
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The whole point of JSTL is that you DON'T use scriptlet code ;-)

JSTL variables are stored in the page, request, session and application scopes.

In java scriptlet code you can get at it like this:


Cheers,
evnafets
 
John Ip
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for that mate!
I did try my best to prevent using scriptlet.... but simple things like if else statement..... is so lengthy to write in the current jstl 2.0 ......
<choose>
<when>
</when>
<when>
</when>
<otherwise>
</otherwise>
</choose>

but with scriptlet

<% if () { %>
<% } else { %>
<% } %>

nice and clean isn't it? Hope the next version of jstl will improve on this.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but simple things like if else statement..... is so lengthy to write in the current jstl 2.0 ......


So?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John Ip:
but simple things like if else statement..... is so lengthy to write in the current jstl 2.0 ......


Well, its lengthy but dont you think its more clear and readable than a scriplet for everyone, a java programmer and a html author? One more positive thing about this is, you dont have to mess up with code and tags. When its about authoring a web page, tag like structure is highly encouraged.

Despite, all these kind of thoughts, isn't it better to follow the conventions and best practices?
[ July 27, 2005: Message edited by: Adeel Ansari ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<% if () { %>
<% } else { %>
<% } %>

nice and clean isn't it?


It might be more terse but I wouldn't call it clean.

I think it would be particularly unclean to have a combination of JSTL and scriptlets in the same page.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!