Simple spring MVC application. I want to populate a form:select in my JSP with a map populated in my Controller.
In my JSP, the form:select is not coming with any options. If I inspect the HTML element from chrome, no options are coming. Elsewhere in my project, the same approach works, but in that case it is an enum.
Brief code snippets follow:
// Domain Class
public class Expense {
String attributeSelectedFromJSP;
Map<String,String> attributesToBeShownInJSP;
...
}
Map is initialised in constructor.
In Controller
Expense exp = new Expense();
// List allEcs is a list of String
for (ExpenseCategory e : allEcs) {
exp.attributesToBeShownInJSP.put(e.toString(), e.toString());
}
modelMap.addAttribute(
"expense", exp);
return new ModelAndView("addExp.jsp",
"command", exp);
In my JSP
<form:form method="POST" action="/addNewExpense"
modelAttribute="expense">
<div class="form-group">
<table >
<tr>
<td>
<form:label path="attributeSelectedFromJSP">Select something: </form:label>
</td>
<td colspan="2">
<form:select path="attributeSelectedFromJSP" class="form-control">
<form:options items="${attributesToBeShownInJSP}" />
</form:select>
</td>
</tr>
For the same class, other string attributes are shown properly. Issue is only with the select options. The same snippet of code works fine in another screen where I used an ENUM.