• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
André-John Mas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic