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

getting indexId from logic:iterate tag

John Smith

Joined: Oct 07, 2003
Posts: 15
here is my sample code from action class. The choices object might vary from ResultSet. I am using two items for testing iterate tag in JSP page.
Collection choices = new ArrayList();
choices.add(new AMSLabelValueBean("Letter", "CL1", "CL2", "CL3"));
choices.add(new AMSLabelValueBean("Card", "CI1", "CI2", "CI3"));
request.setAttribute("choices", choices);

AMSLabelValueBean is just getter and setter method for "intrusiveIndicator" fields.
here is struts-config.xml
<form-bean name="radioForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="control" type="java.lang.String"/>
Here is JSP
<logic:iterate id="choice" name="choices" indexId="idx">
<td><bean:write name="choice" property="label"/></td>
<td><html:radio property="control" idName="choice<%=idx.intValue()%>" value="intrusiveIndicator"/></td>

I am trying to get incremental names for radio buttons, but it says "No getter method available for property control<%=idx.intValue()%> for bean under name org.apache.struts.taglib.html.BEAN". I am not sure that I am providing enouch code. but it would be very helpful if someone can answer. I am just trying to generate dynamic radio buttons depending on result set coming from a database.

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Change the idName attribute in the tag to idName="choice" and it will work if AMSLabelValueBean has a property of "intrusiveIndicator" and a getIntrusinveIndicator() method.

Here's the explanation in the user guide:

If an iterator is used to render a series of radio tags, the idName attribute may be used to specify the name of the bean exposed by the iterator. In this case, the value attribute is used as the name of a property on the idName bean that returns the value of the radio tag in this iteration.

[ March 17, 2005: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
I agree. Here's the link:
subject: getting indexId from logic:iterate tag
jQuery in Action, 3rd edition