This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Struts and the fly likes logic:iterate for counter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "logic:iterate for counter" Watch "logic:iterate for counter" New topic
Author

logic:iterate for counter

Ronan Dowd
Ranch Hand

Joined: Jan 21, 2006
Posts: 84
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>
<%
}
%>


SCJP 1.4 | OCWCD JEE 5
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Ronan Dowd
Ranch Hand

Joined: Jan 21, 2006
Posts: 84
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.
 
GeeCON Prague 2014
 
subject: logic:iterate for counter