I am new to Spring MVC and I am kind of stuck debugging this issue. I fetch some details from my database and send them to the JSP from my controller, and I am able to display it properly. When I am trying to submit the same form back to the controller for some testing purpose, few of the attribute values are null.
class Quote(){
int id;
String name;
//getters and setter
}
class QuotesForm(){
List<Quote> quotesList = new ArrayList<Quote>();
//getters and setters
}
@Controller
class TestController{
@RequestMapping(value = "/update_quotes", method = RequestMethod.POST)
public String updateQuotes(@ModelAttribute("quotesForm") QuotesForm quotesForm,
ModelMap model,
HttpServletRequest request) {
logger.info("update quotes method invoked");
logger.info("quotesForm size " + quotesForm.getQuotesList().size());
for (Quote quote : quotesForm.getQuotesList()) {
logger.info(quote.getId() + " , " + quote.getName());
}
return "/list_quotes";
}
}
This is my jsp (preview)
<form:form id="quotes_form" action="${pageContext.request.contextPath}/update_quotes" method="post" modelAttribute="quotesForm">
<table>
<c:forEach items="${quotesForm.quotesList}" var="quote" varStatus="status">
<tr>
<td> <form:input path="verticalsList[${status.index}].id" value="${quote.id}"/></td>
<td> <form:input path="quotesList[${status.index}].name" value="${quote.name}" readonly="true"/></td>
</tr>
</c:forEach>
<tr>
<td colspan="2"> <input type="submit" value="Update" onclick='$("#quotes_form").submit();' /> </td>
<tr>
</table>
</form:form>
This is my controller log
2014-04-08 10:56:18,486 [http-bio-8080-exec-8] INFO ui.controller.TestController - 1223 , Think like a proton... always positive...
2014-04-08 10:56:18,486 [http-bio-8080-exec-8] INFO ui.controller.TestController - 1224 , The best feeling on earth is love, and the worst feeling on earth is death...
2014-04-08 10:56:18,486 [http-bio-8080-exec-8] INFO ui.controller.TestController - 1225 , You cannot hide from yourself...
2014-04-08 10:56:18,486 [http-bio-8080-exec-8] INFO ui.controller.TestController - 1226 , null
2014-04-08 10:56:18,486 [http-bio-8080-exec-8] INFO ui.controller.TestController - 1227 , null
2014-04-08 10:56:18,486 [http-bio-8080-exec-8] INFO ui.controller.TestController - 1228 , null
2014-04-08 10:56:18,486 [http-bio-8080-exec-8] INFO ui.controller.TestController - 1229 , null
Please help me understand and fix the issue and if you need any info further