Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding delimited strings in textbox to Collection<String>

I have an <form:input type="text" /> element that can take several values, each delimited by a semicolon. For example, it can take a value such as Mike;Jack;Bob.

How can I bind/pass this type of value for an <input> to a Collection<String> in Spring 3 MVC?

like image 469
Donald Taylor Avatar asked Nov 30 '25 14:11

Donald Taylor


1 Answers

You can register a property editor:

@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(Collection.class, 
          new DelimitedCollectionStringEditor());
}

where the editor must extend PropertyEditorSupport

like image 82
Bozho Avatar answered Dec 04 '25 04:12

Bozho