• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

foreach looping and counting

 
Marko Debac
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65217
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
varStatus is an object with properties like count and index.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you guys a lot!

Marko
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic