Reputation: 143
I've got a form in my view which send objects to my controller, but the matter is that I've got an exception if I send more than 256 objects :
org.springframework.beans.InvalidPropertyException: Invalid property 'followers[256]' of bean class [org.myec3.portalgen.plugins.newsletter.dto.FollowerFileDto]: Index of out of bounds in property path 'followers[256]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256
So I was wondering why such a limit, and I found this topic : https://stackoverflow.com/a/24699008/4173394
But it doesnt seem to work for me (probably a bad use from me).
Here is my structure : My view is called createUpdate.vm and post my form like this :
<form id="createFollowerFileForm" method="post" action="#route("followerFileController.upsertFollowerFile")" enctype="multipart/form-data" class="form_styled">
My function upsertFollowerFile in FollowerFileController :
@InitBinder
public void initBinder(WebDataBinder dataBinder) {
// this will allow 500 size of array.
dataBinder.setAutoGrowCollectionLimit(500);
}
@Secured({ "ROLE_SUPER_ADMIN_PORTALGEN", "ROLE_CUSTOMER_PORTALGEN", "ROLE_ADMIN_PORTALGEN", "ROLE_WRITER_PORTALGEN" })
public String upsertFollowerFile(
@ModelAttribute(value = "followerFile") FollowerFileDto followerFileDto,
BindingResult result, ModelMap model, HttpServletRequest request) {
And my class FollowerFileDto :
public class FollowerFileDto {
private String title;
private Long followerId;
private boolean isDeletable;
private List<FollowerDto> followers;
public FollowerFileDto() {
this.followers = new ArrayList<FollowerDto>();
}
As you can see in my controller, I tried to set more than 256 allowed objects (500) with the @InitBinder annotation, but it doesnt work at all. The InitBinder function is never called. Did I do anything wrong ? Thanks for you answers ;)
Upvotes: 8
Views: 5310
Reputation: 867
Spring allow only 255 Objects in a list from <form action="...">
to @Controller
to avoid OutOfMemory
problem. To increase this limit add binder.setAutoGrowCollectionLimit(1000)
in initBinder()
method. WebDataBinder
is a DataBinder that binds request parameter to JavaBean objects. The initBinder()
method must be put in Controller
or parent of the Controller
.
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.setAutoGrowCollectionLimit(1000);
// SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
// dateFormat.setLenient(false);
// binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
Upvotes: 2
Reputation: 143
Actually, the @InitBinder was not read, that's why new collection limit was not set. I had to upgrade my springmvc-router version to 1.2.0 (which also forced me upgrade my spring version to 3.2).
After those upgrades, with the same code, it works ;)
Upvotes: 4