Meaningless Drivel is fun!*
The moose likes JSP and the fly likes foreach looping and counting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "foreach looping and counting" Watch "foreach looping and counting" New topic
Author

foreach looping and counting

Marko Debac
Ranch Hand

Joined: Aug 21, 2006
Posts: 121
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

Joined: Jan 10, 2002
Posts: 61095
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Marko Debac
Ranch Hand

Joined: Aug 21, 2006
Posts: 121
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

Joined: Dec 11, 2004
Posts: 13410

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.



Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

varStatus is an object with properties like count and index.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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


[My Blog]
All roads lead to JavaRanch
Marko Debac
Ranch Hand

Joined: Aug 21, 2006
Posts: 121
Thank you guys a lot!

Marko
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: foreach looping and counting