Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Struts and Indexed Properties

843841May 6 2005
I have searched all over the web and seem to be getting tantalizingly close, but...

I have an ActionForm object ("parentForm") that contains an array of ActionForm objects ("childForm"). In my jsp page, I want to be able to set the value of multiple childForms (using text areas).

Both ActionForm classes are listed in the struts-config.xml file.

---------

The relevant portion of my ParentForm class looks like this:

// variable
private ChildForm[] children = new ChildForm[10];

// constructor
public ParentForm()
{
super();
// initialize children
for(int i = 0; i < children.length; ++i)
{
children[i] = new ChildForm();
}
}

// getter and setter methods
public ChildForm[] getChildren(){
return children;
}

public void setChilren(ChildForm[] children){
this.children = children;
}

public ChildForm getChildren(int index){
return children[index];
}

public void setChildren(int index, ChildForm child)
{
children[index] = child;
}

The ChildForm object is very simple:

private String name = null;

public String getName(){
return name;
}

public void setName(String name){
this.name = name;
}

My jsp page looks like this:

<html:form method="post" action="action.do">
<logic:iterate name="parentForm" property="children" id="child">
<html:textarea indexed="true" name="child" property="name" cols="40" rows="3"/>
</logic:iterate>
<html:submit/>
</html:form>

The generated HTML seems correct:

<textarea name="child[0].name" cols="40" rows="3"></textarea>
...
<textarea name="child[9].name" cols="40" rows="3"></textarea>

-------------

When the input page comes up, all of the text boxes are created. However, after I enter information into them and submit and the page is redisplayed (b/c of a validation failure), the text areas do not contain any values. In my validate() method after hitting submit, I probe for any children values, but they are all null. There seems to be a disconnect b/w the values I enter in the jsp and what gets updated in the Actionform.

There seems to be a lot of different ways to do this thing on the web, although none of them seemed to work for me. This appeared to be the cleanest method. Any ideas?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 3 2005
Added on May 6 2005
0 comments
188 views