Hi,
Im using struts 1.1.
class OtherObj {
private String name;
privae String value;
}
class MyObj {
private id;
private ArrayList<OtherObj> param = new ArrayList<OtherObj>();
public OtherObj getParam(int index) {
while (index >= this.param.size())
this.paramt.add(new OtherObj());
return (OtherObj)this.param.get(index);
}
}
class myForm extends ActionForm {
private ArrayList<myObj> myList = new ArrayList<myObj>();
public MyObj getMyList(int index) {
while (index >= this.myList.size())
this.myList.add(new MyObj());
return (MyObj)this.myList.get(index);
}
}
Now my problem is this:
<input name="myList[0].param[0].name">
The method getMyList is invoked and an object is added, but getParam not is invoked and OtherObj isn't added to ArrayList param. And so i get an exception range out bond.
I didn't understand because invoke only method get of first property myList[0] and for param[0] not!?
I hope, now is more clear, thanks.
<bean:define name="myForm"property="param" id="element"/>
<%
ArrayList<MyObj> list = (ArrayList<MyObj>) element;
%>
<input name="<%=list.get(0).getParam(0).getName()%>" type="text" />
and make sure myForm form bean name is being declared for class myForm under struts-config.xml
Hope tht might help :)
REGARDS,
RaHuL
>public OtherObj getParam(int index) {
>while (index >= this.param.size())
>this.paramt.add(new OtherObj());
>return (OtherObj)this.param.get(index);
>}
What's the object paramt ?
add a debug info to you method to see if it's called:
public OtherObj getParam(int index) {
System.out.println("getParam called with index "+index);
while (index >= this.param.size()){
this.paramt.add(new OtherObj());
System.out.println(" *** Added new Object ");
}
return (OtherObj)this.param.get(index);
}
>Struts see only the frist level of indexed property
That's true.
Try this:<nested:nest property="myList[0]">
<html:text name="param[0].name">
</nested:nest>
or this:<nested:nest property="myList[0]">
<nested:nest property="param[0]">
<html:text name="name">
</nested:nest>
</nested:nest>
See http://struts.apache.org/1.2.7/userGuide/struts-nested.html
Hope That Helps
This is the correct sintax:
<nested:nest property="myList[0]">
<nested:nest property="param[0]">
<nested:text property="name">
</nested:nest>
</nested:nest>
But the problem is the same... when i click sumbit only getMyList(int index) is invoked... and getListParam() not getListParam(int index)!!!
whyyyyy?