I am not sure if this is a complex problem but as a starting person this seems a bit complex to me. I have an object based on which i need to show some values on the UI and
Explanation : if in you controller you have @ModelAttribute("user") User user, and you load a corresponding page that contains <form:form commandName="user">, an empty User is instantiated.
All its attributes are null, or empty in case of a List or a Map. Moreover, its empty lists/maps have been instantiated with an autogrowing implementation. What does it mean ? Let's say we have an empty autogrowing List<Coconut> coconuts. If I do coconuts.get(someIndex).setDiameter(50), it will work instead of throwing an Exception, because the list auto grows and instantiate a coconut for the given index.
Thanks to this autogrowing, submitting a form with the below input will work like a charm :
<form:input path="coconuts[${someIndex}].diameter" />
Now back to your problem : Spring MVC autogrowing works quite well with a chain of objects, each containing a map/list (see this post). But given your exception, it looks like Spring doesn't autogrow the possible objects contained by the autogrowed list/map. In Map<String, List<PrsCDData>> prsCDData, the List<PrsCDData> is a mere empty list with no autogrowing, thus leading to your Exception.
So the solution must use some kind of Apache Common's LazyList or Spring's AutoPopulatingList.
You must implement your own autogrowing map that instantiates a LazyList/AutoPopulatingList for a given index. Do it from scratch or using some kind of Apache Common's LazyMap / MapUtils.lazyMap implementation (so far I have not found a Spring equivalent for LazyMap).
Example of solution, using Apache Commons Collections :
public class PrsData {
private Map<String, List<PrsCDData>> prsCDData;
public PrsData() {
this.prsCDData = MapUtils.lazyMap(new HashMap<String,List<Object>>(), new Factory() {
public Object create() {
return LazyList.decorate(new ArrayList<PrsCDData>(),
FactoryUtils.instantiateFactory(PrsCDData.class));
}
});
}
}