I have a class User{ Set.....} Car{String id,......}. a select box in html page. I want that when user submit form, value of select box should be set in Set. How can i do it in Spring mvc.
A:
When you use Spring's form
tag library, it allows you to bind the form directly to a Java object on the model. The form values will reflect the corresponding values of the model object.
For example, if you have a select box for user.title
, and the possible values come from another model object collection named titles
and containing "President", "CEO", and "Developer", you can use the following:
<form:form modelAttribute="user">
...
<form:select path="title" items="${titles}" />
...
...then the HTML select will automatically reflect the value to which user.title has been set.
James Earl Douglas
2010-09-21 02:12:06