How do I Simplify a text array in a Struts form using a loop

D

Dean Rettig

Inside the ActionForm "reportform" I have this:

<html:text property="selection[0]"/><bean:write name="reportform"
property="label[0]"/><br>
<html:text property="selection[1]"/><bean:write name="reportform"
property="label[1]"/><br>
<html:text property="selection[2]"/><bean:write name="reportform"
property="label[2]"/><br>
<html:text property="selection[3]"/><bean:write name="reportform"
property="label[3]"/><br>
<html:text property="selection[4]"/><bean:write name="reportform"
property="label[4]"/><br>
<html:text property="selection[5]"/><bean:write name="reportform"
property="label[5]"/><br>


Is there any way to do this as a loop? My ActionForm knows how many
items are in the array but my JSP doesn't. My form also knows what
the labels are so I need the loop to iterate thru both {selection and
label} arrays at the same time.

I've spent 6 hours on this and given up....

thanks,
Dean
 
S

Sudsy

Dean said:
Inside the ActionForm "reportform" I have this:
Is there any way to do this as a loop? My ActionForm knows how many
items are in the array but my JSP doesn't. My form also knows what
the labels are so I need the loop to iterate thru both {selection and
label} arrays at the same time.

I've spent 6 hours on this and given up....


You need indexed properties. Check out the following article:
<http://www.sudsy.net/technology/struts-advanced.html>
HTH
 
O

Oscar Kind

Dean Rettig said:
Inside the ActionForm "reportform" I have this:

<html:text property="selection[0]"/><bean:write name="reportform"
property="label[0]"/><br>
<html:text property="selection[1]"/><bean:write name="reportform"
property="label[1]"/><br>
<html:text property="selection[2]"/><bean:write name="reportform"
property="label[2]"/><br>
<html:text property="selection[3]"/><bean:write name="reportform"
property="label[3]"/><br>
<html:text property="selection[4]"/><bean:write name="reportform"
property="label[4]"/><br>
<html:text property="selection[5]"/><bean:write name="reportform"
property="label[5]"/><br>


Is there any way to do this as a loop? My ActionForm knows how many
items are in the array but my JSP doesn't. My form also knows what
the labels are so I need the loop to iterate thru both {selection and
label} arrays at the same time.

Have you looked at the tag <logic:iterator> ? It may do what you want.


Oscar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top