Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

logic:iterate for counter

 
Ronan Dowd
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple question, In struts am trying to print a row 5 times. in my action class i set the number of times i wish to print the row.
Correct me if I'm wrong but i dont want to use a logic:iterate as I'm not, in a sense, "iterating" over anything, I want to
basically do a good ol for loop kinda thing. Is there a nice way to do this in struts ? I want to be able to display my index variable
(count in this case) inside the property attribute of "html:text:" as in the below example..
Does anyone know if there is a cleaner way to do this than embedding java in my jsp? thanks..

<%
for (int count=0; count<5; count++)
{
%>
<tr>
<td><html:text property='<%= "recordValue[" + count + "]'/></td> </tr>
<%
}
%>
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Struts <logic:iterate> tag can't do this, but the JSTL <c:forEach> tag can. That's what I'd suggest you use. Just Google "jstl foreach" if you need the syntax.
 
Ronan Dowd
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cheers for that but i can't seem to nest my JSTL count variable inside my
"<%= %>" part. I've posted a new thread (probably didnt explicity need to though) on it. any advice would be great. thanks - Ronan.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic