aspose file tools*
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
Author

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

Adrian Marrero
Greenhorn

Joined: Oct 23, 2007
Posts: 10
Hi,
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 CustomizeAction.java. 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 SubmitAction.java 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(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:1789)
at org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.java:1684)
at org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils.java:1713)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:1019)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
.....
.....


Code:

----struts-config.xml------
<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>
</form-bean>

<action path="/job/selectItn"
type="mricate.action.CustomizeAction"
parameter="selectItn"
name="dbItnForm"
validate="false"
scope="request">
<forward name="showCustomize" path="page.customize" />
</action>

<action path="/job/submitItn"
type="mricate.action.SubmitAction"
parameter="submit"
name="dbItnForm"
validate="false"
scope="request">
<forward name="showSubmit" path="/do/job/jobStatus"/>
<forward name="showHome" path="page.tiles"/>
</action>

------CustomizeAction.java------
ArrayList filteredList = getFilteredList();
DatabaseItn dbItn = (DatabaseItn)form;
dbItn.setItnModules(filteredList);

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


------SubmitAction.java---------

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


-----DatabaseItn.java----(Master 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);
}
else
{
itnModules.add(mb);
}
}
------ModuleBean.java-----(First Level of Bean)----

String displayName;
String description;
PropertyBean[] properties;

getter and setter methods for each field.

------PropertyBean.java---(Second 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"/>
</nested:iterate>
</logic:iterate>
<html:submit>Submit Job</html:submit><html:reset value="Reset Job Parameters"/>
</html:form>
Saritha Sarla
Greenhorn

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

Thanks
Adrian Marrero
Greenhorn

Joined: Oct 23, 2007
Posts: 10
Saritha,

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"%>'/>
</logic:iterate>
</logic:iterate>

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
Greenhorn

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


Thanks,<br />Sarayu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with using a List of Collections which has another List of Collections