2015-11-05 91 views
0

我有一个bean AgreegateBean,我正在使用它作为传输对象。豆的类定义为 -春季索引超出限制MVC

Class AgreegateBean { 

private SomeOtherBean bean; 
private List<Person> someList; 

// getters and setters 
} 

我在使用ModelAttribute注释的Spring控制器中使用此bean。对于JSP,我有JSTL。我用这样的字段填充了JSP。

<input type="text" name="someList[0].name" /> 
<input type="text" name="someList[0].surName" /> 

当我提出我的形式我得到java.lang.IndexOutOfBoundsException:指数:0,大小:0

org.springframework.beans.InvalidPropertyException: Invalid property 'someList[0]' of bean class [com.form.bean.AgreegateBean]: Index of out of bounds in property path 'someList[0]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 

回答

1

这是因为在检索List<Person> someList;

没有元素前检查:

<c:if test="${someList != null}"> 
    <input type="text" name="someList[0].name" /> 
    <input type="text" name="someList[0].surName" /> 
</c:if> 
+0

我不认为这是问题,因为OP提到“提交”表单。我认为这更多Spring并没有创建'Person'的新实例。 – Tunaki

1

得到了解决。没有使用泛型在getter和setter中。不知道如何,但添加仿制药解决了这个问题。