Ed,
You can find examples of this by searching the archive for indexed
properties. You are getting this exception because the Form collection
does not have enough entries to support the property that you are trying to
populate. You need to insure that the getter that returns a single bean in
the collection (for a given index) creates bean entries in the collection
up to the index that you are trying to retrieve.
There are a few ways to do this. My getter method:
public CollectionBean getCollectionName(int index) {
while(index >= collectionName.size()) {
collectionName.add(new CollectionBean())
}
return (CollectionBean)collectionName.get(index);
}
"Webb, Ed"
<[EMAIL PROTECTED] To: [EMAIL PROTECTED]
mation.com> cc:
Subject: Using a collection of
Beans within an ActionForm
11/19/2003 07:11 AM
Please respond to "Struts
Users Mailing List"
I need to display several lists of choice to the user. These lists are
variable in length depending on the user. I use an ActionForm which contain
Lists. I populate these with objects that contain String and boolean
properties (name of option and selected flag). I add this to the request
scope under the mapping.getAttribute() key and everything is displayed fine
in my JSP page. However when it comes time to submit the changes a new
ActionForm is created with empty Lists and unsurprisingly I get the error
message:
exception:
javax.servlet.ServletException: BeanUtils.populate
...
root cause:
java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
...
Here's a snippet from the JSP page to show how I'm displaying the
information:
...
<c:forEach varStatus="status" var="media" items="${emailalertForm.media}">
<tr>
<td><fmt:message key="${media.mediaName}" /></td>
<td><html:checkbox
property="media[${status.index}].selected" /></td> </tr>
</c:forEach>
...
The question is how can I display lists of choices to the user and get the
changes the user makes to the checkboxes back to my Action? I've read about
nested beans but the only examples I found only had a single bean and not a
collection. Is it possible or is there a better way to go about this?
Thanks for any advice or pointers,
Ed!
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]