I have a problem with the Spring AutoPopulatingList. My use case is the following : manage the list of users that can access an application.
On the GUI side, I use an autocomplete field to search and add users to a table on the right. Users can also be removed from the table. When the GUI user submits, the GUI dynamically builds a form with fields for the users : selectedUsers[1], ..., selectedUsers[N].
My problem is that the AutoPopulatingList in my "backing" bean seems to grow only to 256 items, and then stops. So I get the following error :
[myapp.web.controller.admin.form.ApplicationForm]: Invalid list index in property path 'selectedUsers[256]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256
Do you know if there is the actual limit ? If it is, is there a way to raise it ? If not, can you think of a workaround for this problem ?
Thanks in advance for your help
Ok, so I dug a little more into Spring's internals and found that by default, 256 is the limit.
The limit is given by the BeanWrapperImpl#autoGrowCollectionLimit attribute. Spring's WebDataBinder default configuration sets this to 256.
The proper way to raise this limit is to define a @InitBinder annotated method in your controller :
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.setAutoGrowCollectionLimit(1024);
}
and then everything works as expected.
I did not try to find a way to modify this limit globally.
HTH
In Java, List
are 0-indexed. The first index is then selectedUsers[0]
and the last one is selectedUsers[255]
if the list contains 256 elements.
It seems that you are trying to access selectedUsers[256]
(the 257th element) while the list only contains 256 elements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With