2015-11-05 90 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中。不知道如何,但添加仿製藥解決了這個問題。