I followed the code from http://viralpatel.net/blogs/spring-mvc-multi-row-submit-java-list/ to post a list of objects to my Spring Controller. Soon, I ran into IndexOutOfBoundsException when the list size reached 256.
I found an answer which said setting the setAutoGrowCollectionLimit in WebDataBinder would solve this issue. So in my controller I did:
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.setAutoGrowCollectionLimit(2048);
}
@RequestMapping(value="/upload", method=RequestMethod.POST)
public String postData(Model model){
List<Products> products = //Some processing to get products list
ProductList productList = new ProductList();
productList.setProducts(products);
System.out.println(“Total records loaded: "+products.size());
model.addAttribute("productform", productList);
return “upload”;
}
@RequestMapping(value=“/process”, method=RequestMethod.POST)
public String uploadProcessedData(@ModelAttribute("productform") ProductList productList){
System.out.println(“Total records received: “+productList.getProducts().size());
return "upload";
}
My JSP code:
<form:form method="post" action="${pageContext.request.contextPath}/process” modelAttribute="productform">
<table>
<tr>
<th>Record</th>
<th>name</th>
</tr>
<c:forEach var="product" items="${productform.products}" varStatus="status">
<tr>
<td><c:out value="${status.index + 1}" /></td>
<td><input name="products[${status.index}].name” value="${product.name}”/></td>
</tr>
</c:forEach>
</table>
<input type="submit" value="Save" />
</form:form>
However, my form has 1000+ records and the controller only receives 556 records. Why this number? Is this because of any size limit? How can I get Spring to load all the 1000+ records.