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

foreach looping and counting

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello cowboys,

I have a problem with creating dinamic table where every second row must has same colour, with jstl ofcourse;

so I have



class="red_row" is defined in css.

Can it be done somehow with pure jstl, with no scripting code?

Regardes,
Marko
 
Sheriff
Posts: 67747
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
Yes.

Do you have a copy of the JSTL Specification handy? If not, you should.

When you get it, look up the varStatus attribute to <c:forEach>.

You will be pleased.
 
Marko Debac
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,

but varStatus is a String, I canot use him like "i", i.e. I canot do mod operation on him, so I cant get it, I have download jstl spec, bat its very poor explanation, with no examples

help
 
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

Originally posted by Marko Debac:
Hi Bear,

but varStatus is a String, I canot use him like "i", i.e. I canot do mod operation on him, so I cant get it, I have download jstl spec, bat its very poor explanation, with no examples

help



From the JSTL Spec:


Chapter 6 Iterator Actions 39
6.1.3 Iteration Status
<c:forEach> also exposes information relative to the iteration taking place. The example below creates an HTML table with the first column containing
the position of the item in the collection, and the second containing the name of the product.

See Chapter 16 �Java APIs" for details on the LoopTagStatus interface exposed by the varStatus attribute.

 
Ben Souther
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
varStatus is an object with properties like count and index.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe we have different spec. Mine is very clear

varStatus
Name of the exported scoped variable for the status of the iteration. Object exported is of type
javax.servlet.jsp.jstl.core.LoopTagStatus. This scoped variable has nested visibility.


Now if you look at the JSTL API, you'll find more about LoopTagStatus:
http://java.sun.com/products/jsp/jstl/1.1/docs/api/index.html
 
Marko Debac
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you guys a lot!

Marko
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic