I have a List<String>
in the controller which im passing to the view. I need to populate <form:select>
with that data.
I tried setting the itemValue
attribute to "name"
but that did not work.
You can do the following:
<form:select path="selectName">
<form:option value="0" label="Select an Option" />
<form:options items="${nameOfList}" />
</form:select>
By providing only the items attribute to the form:options tag, it should make the value and label the value of each String in your list.
you can also try as follows:
<form:select path="country">
<form:option value="NONE" label="--- Select ---" />
<form:options items="${countryList}" itemValue="value" itemLabel="description"/>
</form:select>
protected Map referenceData(HttpServletRequest request) throws Exception {
Map referenceData = new HashMap();
Map<String,String> country = new LinkedHashMap<String,String>();
country.put("US", "United Stated");
country.put("CHINA", "China");
country.put("SG", "Singapore");
country.put("MY", "Malaysia");
referenceData.put("countryList", country);
}
Then
<form:select path="country" items="${countryList}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With