nested indexed property

Hiwith<inout name="list[0].param[0].id">The method getList is invoked, but method getParam isn't and i retrive an exception outbound.public objParam getList(int index) {//}public obj getParam (int index) {}
[276 byte] By [davide.angela] at [2007-11-27 6:34:56]
# 1
HELP PLS!
davide.angela at 2007-7-12 18:01:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
hiplease explain your problem clearlythank youregardsbachi
bachea at 2007-7-12 18:01:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
He has a two-dimensional collection and he want to iterate through the 2nd collection without gently declaring a property for it.
BalusCa at 2007-7-12 18:01:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

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.

davide.angela at 2007-7-12 18:01:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

<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

RahulSharnaa at 2007-7-12 18:01:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

>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);

}

java_2006a at 2007-7-12 18:01:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
My problem isn't during ITERATE.The problem is getting the values after press submit using a double index property. understand?
davide.angela at 2007-7-12 18:01:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
parmt is an error while i posted.Yes i added debug info, never enter in the method.
davide.angela at 2007-7-12 18:01:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
struts<input name="myList[0].param[0].name">invoke only getMyList(index) and getParam() not getParam(int index).Struts see only the frist level of indexed property. Anyone know if is possibile use second level too?
davide.angela at 2007-7-12 18:01:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10

>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

java_2006a at 2007-7-12 18:01:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

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?

davide.angela at 2007-7-12 18:01:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12
What's the method signature for indexed field ?With nest tag is invokedgetList() and getParam()i want what it call getList(int index) and getParam(int index)
davide.angela at 2007-7-12 18:01:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...