I've got a problem relating to the validation of indexed properties in Struts 1.1
I get the following error message when I try to access an ArrayList of Student objects in my DynaValidatorForm
Here is some background to the problem...
In my session I have an ArrayList called studentsList of objects of type experiment.mybeans.Student. A Student object has getter and setter methods for id, year and gradeAverage.
In my students.jsp I create a table by iterating through my student objects like this...
As you can see the table contains empty text boxes and I would like to validate these have been filled in, so in struts-config.xml I create my dynavalidatorform as follows...
And in validation.xml I place my validation rules...
Now here is where things start to go a bit pear-shaped
I have read somewhere online that I need to populate the form ArrayList before I get to my jsp page. So I have created an action class called PreStudentsAction.java which takes the student ArrayList out of the session and assigns it to the student ArrayList in the form before forwarding to the students.jsp page...
Finally when I run my application my table is displayed but when I fill in the table and press submit I get the IndexOutOfBounds error. It appears to me that the student ArrayList in the form remains empty and that my Action class was unsuccessful in populating the form's ArrayList.
I had the same exception, but my error was in the query class. do you use any database query?
Joined: Nov 28, 2006
Thanks for your suggestion.
But I only use a database query on my log in page. I don't use db query for this part of the application so I think it's unlikely to be the problem.
The problem, I think, is that the ArrayList in my form is not being instantiated by my Action class so its size = 0, when I try to place my Student objects into the form's students ArrayList it wont 'fit' hence the index out of bounds exception. But I dont know why or what I need to do to instantiate the form's ArratList
Joined: Jan 31, 2010
i dont know(i am new to struts) why do you use ,
Group group = (Group)request.getSession().getAttribute("group");
ArrayList<Student> students = group.getStudentsList();
In your case you get your List of CCBean objects from your form and assign it to a variable in your Action class called cCList.
My case is different in that I need to put an ArrayList into my Form. This ArrayList is an attribute of an object called 'group' which is in my session.
So what I am doing (and I don't know if this is the best way to do it)...
Group group = (Group)request.getSession().getAttribute("group"); // take the Group object from the session and assign it to a variable called group
ArrayList<Student> students = group.getStudentsList(); // then get the student list from group and assign it to a variable called students
I then want to put the students list into my form but unfortunately its not happening for me, dont know why. I may try to come at this from a different angle when I get a chance to look at it again tonight, thanks for your interest.