Announcement Announcement Module
No announcement yet.
Custom PropertyEditor for Collections Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom PropertyEditor for Collections

    I can't find very good documentation how to do this and/or examples and/or a clean, appropriate solution.

    Here goes...

    I have a simple domain model:

    User (1) --> (*) Address

    User object has a Collection of Address objects.

    On the HTML (JSP) side, a user of the web page can dynamically add addresses to the form via JavaScript and DHTML.

    When I submit the form, the Address collection is empty and I get bind errors. This has been discussed already with no clean and appropriate solution.

    I want to make a custom property editor for my collection, which will instantiate the Address objects, populate them and put them in the collection.

    I can't seem to register my custom editor so that Spring uses it for my collection.

    In initBinder()...
    binder.registerCustomEditor(Collection.class,"addr esses",new MyEditor());

    In HTML (User is my command object)...

    <input type="text" name="addresses[0].street" value=""/>
    <input type="text" name="addresses[0].zip" value=""/>
    <input type="text" name="addresses[1].street" value=""/>
    <input type="text" name="addresses[2].street" value=""/>


    What am I doing wrong and/or is there better documentation about the semantics of the first and second parameters to registerCustomEditor(...) besides the API docs?