I'm starting with spring mvc and I would like to know how to fill select
, I have seen examples on the Internet but they are not very clear, I do not know if there is a simple and clear way, I know that the form:options
is used but I would like a complete and detailed example with its drivers, complete jsp files, I found this example code
@RequestMapping(value="/phone-page")
private ModelAndView selectTag() {
ModelAndView mav = new ModelAndView("phone-form");
Map< String, String > phones = new HashMap<String, String>();
phones.put("samsung", "SAMSUNG");
phones.put("nokia", "NOKIA");
phones.put("iphone", "IPHONE");
mav.addObject("phonesMap", phones);
mav.addObject("smartphone", new Smartphone());
return mav;
}
HTML code
<h1>Phone page</h1>
Select phone:
<form:form method="POST" commandName="smartphone" action="phone-result.html">
<table>
<tr>
<td>
<ul>
<form:select path="phone" items="${phonesMap}"/>
</ul>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit"/>
</td>
</tr>
</table>
</form:form>
My doubts are why is this line necessary?
mav.addObject("smartphone", new Smartphone());
Why does the form have to carry this?
commandName="smartphone"
Thank you.