• Post Reply Bookmark Topic Watch Topic
  • New Topic

save "${Value}" in a scriptlet :-/  RSS feed

 
luis Fernandez
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

i am working with EL, and i am iterating with forEach and so..

i need to save in a scriptlet, a index of that forEach:



<cut value="${offset}"/>

How could i do that?

Thanks !!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
forEach has an attribute called varStatus which you can assign to a variable. It contains reference to the loops index.



There is also count which starts with 1 rather than 0, like index. There are also 2 boolean properties; first and last so you can determine if you are at the beginning or end of the loop.
 
Paul Yule
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I completely understand what you are trying to do but if you are doing a
<c:forEach > on your page there is a varStatus attribute in forEach that will keep track of the current count.

Also, scriptlets are not in a scope accessible to Expression Language (for good reason). If you must use scriptlets to acquire your index you need to make it accessible to your EL inside your scriptlet.


[ June 20, 2008: Message edited by: Paul Yule ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
144
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you mixing scriptlets and the EL? They are not meant to be used together and you're likely to just end up with a big old mess.
 
luis Fernandez
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

thanks for replying.

.jsp

// I have this with EL.. so it would be easy to reuse this code to pass //(status.index) to the scriptlet and send it to seriesProducer (if it could //be done). option 1



//But as you say.. it would be better to start again and doing it all with //scriptlet: (avoiding EL). option 2






as you see.. i want to insert some data into seriesProducer, and i wanted to take profit of the code i already have, otherwise i'll do it with scriptlet.

best way to do this?

Thanks !!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!