views:

48

answers:

1

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