You don't need to create special class to bind list of elements. Simplest example of binding select with controller:
Controller:
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(HttpServletRequest request, Model model) {
List<String> listString = new ArrayList<String>();
listString.add("hello");
listString.add("world");
listString.add("from");
listString.add("Belarus");
model.addAttribute("listString", listString);
return "index";
}
@RequestMapping(value = "test", method = RequestMethod.POST)
public String test(@RequestParam String selectedString, Model model) {
System.out.println(selectedString);
return "index";
}
index.jsp:
<form class="form-horizontal" action="${home}/test" method="post">
<select name="listString" class="form-control">
<c:forEach items="${listString}" var="item" varStatus="count">
<option value="${count.index}">${item}</option>
</c:forEach>
</select>
<button type="submit" class="btn btn-primary btn-medium">Submit</button>
</form>
With that code after submitting form you will see selected items indexes in console.
If you want to transport also initial list (listItem) you can make another select with all items selected and attribute multiple="multiple"
and set its style to display: none; After this declare another param @RequestParam List<String> listString
and you'll get your initial array of strings.
About adding param:
return "myController/index"; // <- want to add as query param: ?item=theItem
You can't pass parameter that way. Thats because you return name of view (tiles of simply name of jsp), but not url. If you want to go to url with param you can make:
return "forward:/index?item=theItem";
Hope it helps