File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Help with using a List of Collections which has another List of Collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Help with using a List of Collections which has another List of Collections" Watch "Help with using a List of Collections which has another List of Collections" New topic

Help with using a List of Collections which has another List of Collections

Adrian Marrero

Joined: Oct 23, 2007
Posts: 10
I have been at this for several days, looked through several forums, and I have yet to find the answer to my problem.

Overview of my scenario:
I have a bean (ModuleBean)that has several fields, one of these fields is a list of another bean (PropertyBean) with several fields as well. In the code I am obtaining a list of ModuleBeans and adding that list to an ArrayList. I am able to properly display the fields that I am interested in on my JSP page and allow the user to update them, but I can not find a way to send the entire list of ModuleBeans with the updated PropertyBean fields back to my servlet once the JSP page has been submitted.

Flow of information:
The information is first constructed in the servlet The customize jsp page is then constructed with the information set by this servlet, which in turn is going to ideally send the information to the servlet so I can manipulate that information there.

Result: I continually get the error IllegalArgument: argument type mismatch error where I see the following error.(I do not have access to my precise error message but it is extremely similar to this one, if not exact).

java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke( Code))
at java.lang.reflect.Method.invoke( Code))
at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(
at org.apache.commons.beanutils.PropertyUtils.setNestedProperty(
at org.apache.commons.beanutils.PropertyUtils.setProperty(
at org.apache.commons.beanutils.BeanUtils.setProperty(
at org.apache.commons.beanutils.BeanUtils.populate(
at org.apache.struts.util.RequestUtils.populate(


<form-bean name="dbItnForm" type="mricate.bean.DatabaseItn">
<form-property name="databaseName" type="java.lang.String" />
<form-property name="itnId" type="java.lang.String" />
<form-property name="itnName" type="java.lang.String" />
<form-property name="itnDescription" type="java.lang.String" />
<form-property name="jobId" type="java.lang.String" />
<form-property name="jobName" type="java.lang.String" />
<form-property name="jobStatus" type="java.lang.String" />
<form-property name="itnModules" type="java.util.ArrayList"></form-property>

<action path="/job/selectItn"
<forward name="showCustomize" path="page.customize" />

<action path="/job/submitItn"
<forward name="showSubmit" path="/do/job/jobStatus"/>
<forward name="showHome" path="page.tiles"/>
ArrayList filteredList = getFilteredList();
DatabaseItn dbItn = (DatabaseItn)form;

ArrayList getFilteredList()
ArrayList list = new ArrayList();
for(int i = 0; i < numberOfModuleBeans; i++)
list.add(new ModuleBean());
return list;

DatabaseItn dbItn = (DatabaseItn)form;
ArrayList list = dbItn.getItnModules(); Bean)---

There are several fields in this Bean but I am only interested in the one that I am going to show below. The last two methods I created so that the "id" attribute of the iterate tag can properly access the ArrayList.

private ArrayList itnModules = new ArrayList();

public ArrayList getItnModules()
return this.itnModules;

public void setItnModules(ArrayList itnModules)
this.itnModules = itnModules;

public ModuleBean getModules(int index)
if(index >= itnModules.size())
while(itnModules.size() <= index)
itnModules.add(new ModuleBean());
return (ModuleBean)itnModules.get(index);

public void setModules(int index, ModuleBean mb)
if(index < itnModules.size())
itnModules.set(index, mb);
} Level of Bean)----

String displayName;
String description;
PropertyBean[] properties;

getter and setter methods for each field. Level of bean)----

String displayName;
String description;
String value;
Integer typeId;

getter and setter methods for each field.

-------Customize JSP----------
<html:form action="/job/submitItn" method="post">
<logic:iterate id="modules" name="dbItnForm" property="itnModules">
<bean:write name="modules" property="displayName"/>
<nested:iterate name="modules" property="properties">
<nested:write property="displayName"/>
<nested:text property="value" indexed="true"/>
<html:submit>Submit Job</html:submit><html:reset value="Reset Job Parameters"/>
Saritha Sarla

Joined: Oct 23, 2003
Posts: 6
did you find the answer for this.
I have the same problem. Can you help me if you do.

Adrian Marrero

Joined: Oct 23, 2007
Posts: 10

It has been a few months since I had this issue, but here is what I remember.
First of all, everything anyone always told me was to stay away from: indexed = "true". It causes all sorts of issues when you are trying to alter nested beans inside of other beans. I had to manually map the location of where I wanted the information stored using the attribute "indexId". Here is an example of what I did:
<logic:iterate id="modules" name="customData" property="userMods" indexId="moduleIndex">
<logic:iterate id="moduleProps" name="modules" property="property" indexId="propIndex">
<bean:write name="moduleProps" property="displayName"/>
<html:text name="customData" property='<%="userMods["+ moduleIndex +"].properties["+ propIndex +"].value"%>'/>

If try that out and if it doesn't work I will try to look for another example. I hope this works for you, it did for me. Let me know.
Sarayu Kannan

Joined: Feb 11, 2008
Posts: 2
Use struts-nested tags....
About Struts-nested tags

Thanks,<br />Sarayu
I agree. Here's the link:
subject: Help with using a List of Collections which has another List of Collections
It's not a secret anymore!