File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes struts: JSP, iterator and display a list as a grid Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts: JSP, iterator and display a list as a grid" Watch "struts: JSP, iterator and display a list as a grid" New topic
Author

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

André-John Mas
Ranch Hand

Joined: Oct 18, 2008
Posts: 37
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Oct 18, 2008
Posts: 37
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

Joined: Sep 29, 2008
Posts: 12617

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts: JSP, iterator and display a list as a grid
 
Similar Threads
Displaying the fields in an order
Html Lists CSS Query
Using EL to loop through a List and display all its properties
Transfer the variable value from one jsp page to other
Ordered List tag inside jsp