<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=blurryrunner" rel="nofollow">Stephen Todd</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-3450?redirect=false" rel="nofollow">SPR-3450</a></strong> and commented</p>
<p dir="auto">Spring's current code makes it difficult to use java collections as a command in command controllers. Specifically, referencing elements in the collection is prevented. Currently, elements in an collection are references using []. Support needs to be added to allw paths to start with [index/key] as in "[1].property".</p>
<p dir="auto">The application for this is probably rare, which is probably why it hasn't been brought up before (at least I couldn't find an similarly reported issues). I use the functionality for executing multiple of the same commands. I currently have a form that has multiple objects that can be selected. If the user clicks "Delete" with multiple objects selected, I have an array of id's that get passed to a delete form. This form creates a delete command for each object specified. Details for the way the objects are deleted are stored in an object, which is put in to a list. When the user submits the form, each command is executed in succession (the list is actually passed to the business layer and executed in a single transaction).</p>
<p dir="auto">The current work around is to create a subclass of the java collection you want and make a getter that returns this. Then you can reference the array as (using a getter getSelf()) "self[1].property". Although this method works, a method that doesn't require this simple extension would be preferable.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0.4</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=aantono" rel="nofollow">Alex Antonov</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-2058?redirect=false" rel="nofollow">SPR-2058</a></strong> and commented</p>
<p dir="auto">When a BeanWrapper wraps an object that is a map or a collection of sorts, it has trouble retrieving a value using a key property<br>
i.e.<br>
Person p = new Person("John");<br>
Map map = new HashMap();<br>
map.put("key", person);<br>
BeanWrapperImpl wrapper = new BeanWrapperImpl(map);<br>
String name = wrapper.getPropertyValue("[key].name")</p>
<p dir="auto">This kind of access is very possible when comming from a web-layer using a bind-path of something like [key].name when the top-level object is itself a map.<br>
In this case, when calling errros.rejectValue("[key].name", ...) in the validator, the call throws an exception due to inability to find an object referenced by [key].</p>
<p dir="auto">Currently a work-around this problem is to subclass a map and provide a getter for every key you might have in the map, so that the path looks like key.name, but<br>
this approach requires a lot of overhead of the getter creation.</p>
<hr>
<p dir="auto">11 votes, 9 watchers</p>