Java – Bind Map in spring mvc


I have a form in spring mvc 2 having command class "Class1"

I want to bind Class3 elements with an input field in this form. Below are my classes.

I am iterating/binding over Class2 elements in JSP other than map like this

<c:forEach var="item" items="${class1.class2List}" varStatus="itemsRow">  
    <form:input path="class2List[${itemsRow.index}].anyElement2" />

My Classes looks like

List<Class2> class2List;
String anyElement1;

Map<String, Class3> class2Map;
String anyElement2;

Map<String, Class3> class3Map;
String nameToGet;
String anyElement3;

How can I bind anyElement3 inside class3Map. Is it possible?

Edited for first Answer

Caused by: org.springframework.beans.NullValueInNestedPathException: Invalid property 'class2List[0].class2Map[0]' of bean class [com.Class1]: Could not instantiate property type [com.Class3] to auto-grow nested property path: java.lang.InstantiationException: com.Class3
    at org.springframework.beans.BeanWrapperImpl.newValue(

Best Solution

Assuming your class2Map has an entry with key, say, mapkey, try this:

<form:input path="class2List[${itemsRow.index}].class2Map['mapkey'].anyElement3" />