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>
&开发者_如何学Golt;/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?
I solved the problem just by prepopulating the map and arrays inside the map objects. So to create it, use
@ModelAttribute(FORM_PRECRUISE_SHOPPING)
@Valid
PrecruisePlannerShoppingForm form
精彩评论