wood burning stoves
The moose likes JSP and the fly likes JSTL - total count for loop within a loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL - total count for loop within a loop" Watch "JSTL - total count for loop within a loop" New topic

JSTL - total count for loop within a loop

Garret O'Keeffe

Joined: Nov 27, 2008
Posts: 6
Hi - here is my dilema,
I need to display items in a html table from a Map using JSTL. Every odd table row should have a grey colour and every even should be white (so it looks nice).
My data is nested in HashMaps. The first map provies a key to the second map. However the second map may have differnt sizes for its different keys.
I want to display all the data from the second map for all the data in the first. At the moment I am testing for odd/even by checking if the count % 2 = 0 for the first map but because of the varying length of the second map however this is wrong. I need some means of getting the total index and then I can use the module against this.

My constrains are; I can't change the way the maps are and I cannot use scriptlets. How can I do this using JSTL?

Here is a snippet of my current code, I have commented the bad test:-

Any help would be greatly appreciated as I know this is possible but its baffling me

Anirvan Majumdar
Ranch Hand

Joined: Feb 22, 2005
Posts: 261
Before you start iterating over - ${pSysReqMapEntry.value} - initialise a temporary variable -
Once you start the iteration of ${pSysReqMapEntry.value}, simply test and flip the value of this variable -
Hope this helps!
Sri Karr

Joined: Mar 19, 2008
Posts: 9
Please use the variable "counter" to iterate over the inner c:forEach loop and use that to find out even and odd rows.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63208

Please be sure to use code tags when posting code to the forums. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Garret O'Keeffe

Joined: Nov 27, 2008
Posts: 6
Cool - That works great and nice & clean too. Tha
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: JSTL - total count for loop within a loop
It's not a secret anymore!