troubleshooting Question

InvalidPropertyException on trying to bind with ArrayList in a form in Spring MVC

Avatar of lotrzz
lotrzzFlag for United States of America asked on
JavaJSPJava EE
4 Comments1 Solution3447 ViewsLast Modified:
I am getting an invalid property exception when I am trying to bind an collection in my model object in my form object.

This is my model object.
public class Manager{
   private Employee name;
   private Collection<Employee> subordinates;
//getters & setters

//the employee bean looks like this
public class employee{
    private String name;
   private String department;
    private String title;
    //getters & setters

In my manager form displaying, submitting the employee object was  not a problem. But when I tried to display the subordinates in a c:forEach loop and submit form I am getting this:

Invalid property 'subordinates[0]' of bean class []: Invalid index in property path 'subordinates[0]'; Cannot get element with index 0 from Set of size 0, accessed using property path 'subordinates[0]'

here is my  form for your reference

<form:form method="post" action="">
<td><form:label path="">Manager Name</form:label></td>  //this is fine
<td><form:input path="" /></td>
<td><form:label path="name.title">Manager Title</form:label></td>  //this is fine
<td><form:input path="name.title" /></td>
<c:forEach items="${command.subordinates}" varStatus="childIdx">
<td><form:input path="subordinates[${childIdx.index}].name"/></td>
<td><form:input path="subordinates[${childIdx.index}].title"/></td>

This is some kind of a binding issue and I am not sure what to do.  Do I need to use spring:bind in my form?  I am using MVC 3 so I am not sure that I have to explicitly bind. The subordinate list needs to get lazily loaded how do i write a custom editor to do that?  

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros