File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Iterating for non-collection object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Iterating for non-collection object" Watch "Iterating for non-collection object" New topic

Iterating for non-collection object

Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
Hi All,

I am trying to create some sort of dynamic table with different rows and columns. Each cell in the table should contain one checkbox each.

Here's my action form. intColumnCount represents number of columns. intRowCount represents number of rows.

in my JSP i need to display them so I use logic iterate.

But I am getting error Cannot create iterator for this collection.
I am thinking its because, I cant iterate on non-collection object (intColumnCount and intRowCount). I need those two variable so I could generate my <tr></tr> and <td></td> html tags.

Is there a way I can iterate on non-collection object without using scripting? I hope I had explained things clearly. Thanks.

Sean Clark ---> I love this place!!!
Me ------> I definitely love this place!!!
Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
Hi All,

I found my answer to my question but I had to resort to using scripting in my JSP wherein I need to display something like this.

element1 element2 element3
element4 element5 element6
element7 element8 element9

wherein each element represents 1 checkbox. Some sort of a minesweeper game on the web.

I cant find any ways on how to implement this using struts tag alone only.
My JSP looks bad with scripting on it and I cant generate a closing </tr> tag for my JSP also. But either way, my browser interpreted it as is and displayed it correctly.

Hope someone has better idea on how to implement this because I'm trying to avoid scripting in my JSP. But on my own, I think scripting still comes handy in some rare cases, am i right in this? Thanks.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Another option would be to transform your data into a two dimensional array in your action class and then use nested iterate tags. I am not sure this would be a "better" solution but it would get rid of the scriptlet code.

- Brent
I agree. Here's the link:
subject: Iterating for non-collection object
It's not a secret anymore!