Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL - total count for loop within a loop

 
Garret O'Keeffe
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use the variable "counter" to iterate over the inner c:forEach loop and use that to find out even and odd rows.


</c:forEach>
</table>
[/code]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Garret O'Keeffe
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool - That works great and nice & clean too. Tha
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic