I am an old servlet/html guy. I know this should be so straight forward, but I am unable to find an example of what I am trying to do. Perhaps my approach is wrong, but would appreciate some advice.
I am able to load a dropdown list using Spring form tag with a List<> of keys and values I have retrieved from a table, but when the form is submitted, I get an EMPTY List<> (size=0). I am able to retrieve the answer (input=text) from the form.
My Contoller:
@RequestMapping(value = "/getQuestions", method = RequestMethod.GET)
public ModelAndView getQuestionsPage() {
List<Question> questionsList = questionDAO.getAll();
return new ModelAndView("questions", "questionsList", questionsList);
}
@RequestMapping(method = RequestMethod.POST)
public ModelAndView processForm(@ModelAttribute("answer1") String answer1, @ModelAttribute("questionsList") java.util.ArrayList question) {
ModelAndView model = new ModelAndView("home");
return model;
}
Form section of the jsp:
<form action="questions" method="post" modelAttribute="questionsList">
<table>
<tr>
<td>Questions :</td>
<td><form:select path="questionsList">
<form:option value="0" label="Select" />
<form:options items="${questionsList}" itemValue="id" itemLabel="question" />
</form:select>
</td>
</tr>
<tr>
<td>Answer :</td>
<td><input type="text" name="answer1"></td>
<tr>
<td><input type="submit" /></td>
</tr>
</table>
I am thinking it may have something to do with the ??
Any help would be greatly appreciated!