Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring binding values in a Map

Is there a way to Spring bind values in a map?

For instance, I have a Map<String,String> and I want to spring bind specific values in it. The user will type something into a input element, and the value of that input element will get bound to the value associated with a specific key in the map.

like image 500
stevebot Avatar asked Dec 22 '10 17:12

stevebot


1 Answers

Yes, you can do it with [...] syntax. The Map itself, however, should be a property of the command object:

public class Form {
    private Map<String, String> values = ...;
    ...
}

Then you submit a form with the input field named values['foo'], i.e. with Spring form tags it would be a path:

<form:input path = "values['foo']" />

or name in plain HTML:

<input name = "values['foo']" type = "text" />
like image 57
axtavt Avatar answered Nov 20 '22 21:11

axtavt