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

struts - logic:iterator used with html:select

Matt Connors

Joined: Sep 08, 2004
Posts: 23
I have a Collection of IDs. These IDs are of type Integer. I want to iterate over this Collection and for each iteration I want display a dropdown using <html:select....>. Here is the relavent code:

private Collection AdditonalAssignmentIDs = Collections.EMPTY_LIST;

Vector IDs = new Vector();
Collection tasks = TaskAssignmentDat.findActiveByTask(task);
for (Iterator iter = tasks.iterator(); iter.hasNext(); ) {
Task task = (Task);
Integer employeeID = task.getEmployeeId();


<logic:iterate id="ID" name="AdditonalAssignmentIDs"
<html:select styleClass="input" alt="Additional Assignee"
property="ID" size="1">
<html ption value="">--------------</html ption>
<html ptions collection="leaders" property="employeeId"

The compile time error I am running into is:
"javax.servlet.jsp.JspException: No getter method available for property ID for bean under name org.apache.struts.taglib.html.BEAN"

Any ideas on how to resolve this? Do I need to create a bean whose only attribute is an Integer in order to have the getter and setter methods?

Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
<html:select styleClass="input" alt="Additional Assignee" property="ID" size="1">
This is causing Struts to look for the method getID() on your form bean.

You probably need to use the "value" attribute.
<html:select styleClass="input" alt="Additional Assignee" value="ID" property="ID" size="1" >

For the "property" attribute the documentation says:
Name of the request parameter that will be included with this submission, set to the specified value.

Sheldon Fernandes
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

That error about the getter method is not complaining about Integer missing a getter method; it is looking for getID() in your ActionForm.

But add the method and you still have another problem - all of your dropdowns will access the same getter and setter method with no way to tell the difference between them.

This might be a good opportunity for a map-backed solution:

and then change your html:select to -
<html:select styleClass="input" alt="Additional Assignee"
property='<%= "value(" + ID + ")" %>' size="1">

A good workman is known by his tools.
I agree. Here's the link:
subject: struts - logic:iterator used with html:select
jQuery in Action, 3rd edition