Iβm not sure if this is a difficult problem, but as a beginner, it seems a bit complicated to me. I have an object based on which I need to show some values ββin the user interface and allow the user to select some of them, I need to send the data back to another controller when the user clicks the submit button. Here is the structure of my data object
public class PrsData{ private Map<String, List<PrsCDData>> prsCDData; } public class PrsCDData{ private Map<String, Collection<ConfiguredDesignData>> configuredDesignData; } public ConfiguredDesignData{ // simple fields }
I set the object in the model before displaying the view, for example
model.addAttribute("prsData", productData.getPrData());
In the form I have the following settings
<form:form method="post" commandName="prsData" action="${addProductToCartAction}" > <form:hidden path="prsCDData['${prsCDDataMap.key}'] [${status.index}].configuredDesignData['${configuredDesignDataMap.key}'] [${configuredDesignDataStatus.index}].code"/> <form:hidden path="prsCDData['${prsCDDataMap.key}'] [${status.index}].configuredDesignData['${configuredDesignDataMap.key}'] [${configuredDesignDataStatus.index}].description"/> </form:form>
This is what I have in AddProductToCartController
public String addToCart(@RequestParam("productCodePost") final String code, @ModelAttribute("prsData") final PrsData prsData, final Model model, @RequestParam(value = "qty", required = false, defaultValue = "1") final long qty)
When I submit the form, I get the following exception
org.springframework.beans.NullValueInNestedPathException: Invalid property 'prsCDData[Forced][0]' of bean class [com.product.data.PrsData]: Cannot access indexed value of property referenced in indexed property path 'prsCDData[Forced][0]': returned null
It seems to be trying to access the values ββon this controller while I try to pass the value to this controller and trying to create the same object with the selected values
Can someone tell me where I am doing wrong and what I need to take care of
Edit
I did some more research and found out that Spring does not support auto-populating a list / map for custom objects and based on the answer I tried to change the implementation, for example
public class PrsData{ private Map<String, List<PrsCDData>> prsCDData;
but I get the following exception
org.springframework.beans.InvalidPropertyException: Invalid property 'prsCDData[Forced][0]' of bean class [com.data.PrsData]: Property referenced in indexed property path 'prsCDData[Forced][0]' is neither an array nor a List nor a Set nor a Map; returned value was [ com.data.PrsCDData@6043a24d ]
I'm not sure what I'm doing wrong, it seems like either my JSTL expression is not suitable