3

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.

Community
  • 1
  • 1
zambro
  • 414
  • 1
  • 6
  • 17

1 Answers1

2

You might want to add the enctype=multipart/form-data in the form tag for huge data, especially if you have non-ASCII characters in the payload. That might enable sending huge data in chunks.

ggauravr
  • 190
  • 2
  • 11