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 - How to use an ArrayList as a bean?

843838Jul 18 2007 — edited Apr 2 2008
Dear Java Community,

I am using a very old version of struts - Jakarta Struts 1.1 b2 (The Version included in JDeveloper 10.1.2.1.0 for Java 1.4). I have to use this version of struts on the project I am working on because it is the only version compatible with our OC4J Container (Oracle Containers for Java) that runs on the version of our Oracle Application Server we use, that cannot be upgraded due to the reason that we run other programs that cannot be updated on it.

I am developing a form for orders to be entered in line by line in text fields. I have a button for the user to add more rows to this matrix of orders being entered. This dynamically generates <input type="text" name="somebean">. After the page submits it is mapped to action class myForm which extends the ActionForm class from the struts api. This form gets and sets beans.

I have a bean mapped in my struts config for testBox which maps to an ArrayList:

<form-bean name="myForm" type="org.apache.struts.action.ActionForm">
<form-property name="testBox" type="java.util.ArrayList"/>
</form-bean>

I have these as my getter and setter methods for the array:

public class myForm extends AcitonForm{
List testBox = new ArrayList();

public List getTestBox(){
return testBox;
}

public void setTestBox(List value){
testBox = value;
}
}

Now... here's the challenge. How do you configure this to catch the text fields in the ArrayList bean?

When you try to do this on your JSP page:

<input type="text" name="textBox[0]">

Tomcat will give you an array out of bounds index, which makes sense to me; however, I need to know how to enter in data to an ArrayList bean from a textbox. Is this even possible? If not by struts action mapping, could this be done by using AJAX? I do not know. I have spent three days trying to figure this solution out and googled to the end of the earth. I hope someone here can help because I am out of ideas.

Thank you,
Dantevios
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 30 2008
Added on Jul 18 2007
23 comments
6,920 views