框架:spring
现象:jsp页面使用foreach循环输出list,保存时并将修改后的值返回给后台页面。
异常:org.springframework.beans.InvalidPropertyException: Invalid property 'list[256]' of bean class [...]: Index of out of bounds in property path 'list[256]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256
在jsp传值时直接保存,并没有进入后台
原因:DataBinder中有如下定义:
public class DataBinder implements PropertyEditorRegistry, TypeConverter {
/** Default object name used for binding: "target" */
public static final String DEFAULT_OBJECT_NAME = "target";
/** Default limit for array and collection growing: 256 */
public static final int DEFAULT_AUTO_GROW_COLLECTION_LIMIT = 256;
private int autoGrowCollectionLimit = DEFAULT_AUTO_GROW_COLLECTION_LIMIT;
解决方法:在自己的Controller类中,加入以下代码
@InitBinder
protected void initBinder(WebDataBinder binder) {
binder.setAutoGrowNestedPaths(true);
binder.setAutoGrowCollectionLimit(1024);
}