PDA

View Full Version : Multi-select lists


mdavidn
Nov 26th, 2004, 07:02 PM
I've been using maps of integer to boolean values to implement multi-select lists with Spring MVC. Is there a better way? My method requires that I write special code to extract all the "true" entries, lookup the object associated with each integer key, and insert the set of said objects into my domain model. It's really cumbersome and repetitive ... there must be a better way!

Matthew

gmatthews
Nov 28th, 2004, 05:35 PM
Spring will automatically populate a String[] command property if you want to do multiselects.

e.g. if you have a "String[] persons" property in your command object, you could put a corresponding <select multiple name="persons" ...> control in your page, then Spring will call setPersons(String[] selectedValues).

no manual extraction code necessary.

also don't forget to put some javascript code in onSubmit of the form to select all values in the multiselect, otherwise even though they appear in the list, they won't be submitted.

haven't tried this to see if it works for Integer[] properties....