This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

registerCustomEditor to a collection of custom classesPage Title Module

If the field denotes an array or Collection, the PropertyEditor will get applied either to the array/Collection itself (the PropertyEditor has to create an array or Collection value) or to each element (the PropertyEditor has to create the element type), depending on the specified required type.

I interpreted this as meaning that since the field I specified ("myClasses") is a collection, but the class I specified is not a collection "MyClass.class", then DataBinder would use the PropertyEditor to create the elements. But this is not the case. DataBinder basically ignores my customEditor because the type registered "Role.class" doesn't match the actual type "List.class". The list ends up getting populated with Strings, and I end up with a ClassCastException.

So my question is, am I interpreting the JavaDoc right?

Note: as a work around, I created a custom CustomCollectionEditor that takes an instance of a PropertyEditor which it uses to populate a collection.

The name will ultimately resolve to mycollection[3] and it's clear from this notation that the value should be inserted by a PropertyEditor into the 3rd element of the mycollection collection. Each value of the mycollection object will correspond to a single request parameterName / Value pair.

I falsely believed that multiple-select form input elements would be handled by the DataBinder similarly, as you did. Keep in mind that this kind of form input element:

Will result in only one parameter being passed back to the server: a CSV list of the selected elements. It will be a single parameter name / value pair, and as a GET parameter it would look like this:

Code:

http&#58;//foo.com?mycollection=22,234,42,2,234,11,232

There is no way to register a CustomPropertyEditor that will operate on each of the elements implicitly, as someone must first unmarshall that CSV string into individual values.

You can of course register an editor that accepts a string of CSV values as input, unmarshalls the values, and then operates on each value individually. You can find various solutions around this forum that do exactly that.