• 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

struts: JSP, iterator and display a list as a grid

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am wanting to display a grid of items in a JSP. The data is returned as a list from the action. For example:


Now, if I was to use Java code I would simply use two for statements, one for the rows and one for the columns. Since I am wanting to avoid Java code in the JSP, I am looking at the using the iterator to do this, but I am not sure how I would go about it. The result should be something like:



Can someone suggest how I would go about this using iterators?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just sketch out the Java code then do the same thing with the tags and OGNL--the logic is exactly the same.
 
André-John Mas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java I would do this (off the top of my head, as pseudo code ):



I am not sure how I would form the conditions and increment the values using struts2 tags.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the "status" attribute of the iterator tag; you don't need to increment anything manually.

(You could, of course, use <s:set> to set, then increment a value, but it would be pointless in this case.)

The conditions look like typical conditions, but would be used in <s:if> tag "test" attributes.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic