• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Validation of indexed properties

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Can anybody see what I'm doing wrong?


 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had the same exception, but my error was in the query class. do you use any database query?

 
Hugh Roarty
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi daffny,

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
 
daffny nila
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 my case I use ,

FormCCBean formCCBean = (FormCCBean) form;
List<CCBean> cCList = formCCBean.getCCList();

i receive the arraylist from the formbean.
 
Hugh Roarty
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi daffny,

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.
reply
    Bookmark Topic Watch Topic
  • New Topic