File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Arranging list data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Arranging list data" Watch "Arranging list data" New topic

Arranging list data

Dave Mere
Ranch Hand

Joined: Oct 25, 2004
Posts: 37
Hi there,

I have a set of results returned to my jsp as a list of beans. Each bean contains one data field and the name of a thumbnail to find and display. The info needs to be displayed in a fixed table format, like so:

1 2 3 4 5
6 7 8 9 10

I can think of a few ways to acheieve this. For example, set an arbitary variable i to increment with each new record. When i = 6 add another <tr>.
Or, return the results as two sets of 5 and loop through the <logic:iterate> twice so I have two tables.

But both of these seem like applying sticking plasters to a problem that I should really solve! Can anyone suggest a better way of arranging these records in the above format?

Thanks, Dave
[ February 21, 2006: Message edited by: Dave Mere ]
Dave Mere
Ranch Hand

Joined: Oct 25, 2004
Posts: 37
Oops - here's the code, formatted a little better . . .
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Dave: Don't sweat the small stuff. Either of your proposed solutions sounds fine to me. This is presentation logic since all you are doing is displaying data on the page. I would implement this in either the JSP or in my Action Form class.

- Brent
Dave Mere
Ranch Hand

Joined: Oct 25, 2004
Posts: 37
One of my colleagues gave me the same answer. It works doesn't it? Then do it! Perhaps I'm starting to think too much.

cheers brent
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you want this to work for any number of entries (not just 10 or less) you might consider changing the logic to :

if ((currentIndex % 5) == 0)
... add a new row

Consultant, Sima Solutions
I agree. Here's the link:
subject: Arranging list data
jQuery in Action, 3rd edition