我正在尝试将 Map> 与 Spring Framework 绑定,并且出现以下异常:
ERROR [jsp:165] org.springframework.beans.NullValueInNestedPathException: Invalid property 'command.map[key][0]' of bean class
troller.form.CommandForm]: Cannot access indexed value in property referenced in indexed property path 'map[key][0]': returned null
Command 对象是这样的:
public class Command {
private Map<String, AutoPopulatingList<B>> map;
//getters and setters for map
}
B 类就像这样
Public class B {
private String name;
private String age;
}
JSP代码是这样的
<c:forEach var="entry" items="${command.map}">
<c:forEach var="b" items="${entry.value}">
<form:hidden path="command.map[${entry.key}][${status.index}]" />
<c:out value="${b.name}" />
</c:forEach>
</c:forEach>
我想我还应该提到Map是动态的所以我不知道有多少条目或者Map的列表的大小。当我向地图添加新条目时出现问题。
我知道这与初始化 Map 中的列表有关,但这不是为什么建议使用 AutoPopulatedList 这样就不会有任何初始化相关的问题吗?
这可以与 Spring 框架绑定吗?
I'm trying to bind Map<String, org.springframework.util.AutoPopulatingList<B>>
with Spring Framework and I am getting Following Exception:
ERROR [jsp:165] org.springframework.beans.NullValueInNestedPathException: Invalid property 'command.map[key][0]' of bean class
troller.form.CommandForm]: Cannot access indexed value in property referenced in indexed property path 'map[key][0]': returned null
Command object is like this:
public class Command {
private Map<String, AutoPopulatingList<B>> map;
//getters and setters for map
}
And B class is like
Public class B {
private String name;
private String age;
}
and JSP code is like this
<c:forEach var="entry" items="${command.map}">
<c:forEach var="b" items="${entry.value}">
<form:hidden path="command.map[${entry.key}][${status.index}]" />
<c:out value="${b.name}" />
</c:forEach>
</c:forEach>
I think I should also mention that the Map is dynamic so I can't know how many entries there is or which size Map's Lists will be. And problem occurs when I'm adding new entry to map.
I know that this relates to initializing List's in Map but does isn't that why it is recommended to use AutoPopulatingList so there should not be any initialization related problems?
Can this be binded with Spring Framework at all?
发布评论
评论(1)
我只是通过预先填充地图对象内的地图和数组解决了这个问题。
因此要创建它,请使用
I solved the problem just by prepopulating the map and arrays inside the map objects.
So to create it, use