• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

forEach var

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

but simple things like if else statement..... is so lengthy to write in the current jstl 2.0 ......



So?
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic