How to fill in <form: select> with list <String>?

I have a List<String> in the controller that im passes to the view. I need to populate <form:select> this data.

I tried setting the itemValue attribute to "name" , but that didn't work.

+6
source share
3 answers

You can do the following:

 <form:select path="selectName"> <form:option value="0" label="Select an Option" /> <form:options items="${nameOfList}" /> </form:select> 

Providing only the items attribute in the form: options tag, it should make a value and mark the value of each line in your list.

+8
source

You can also try the following:

 <form:select path="country"> <form:option value="NONE" label="--- Select ---" /> <form:options items="${countryList}" itemValue="value" itemLabel="description"/> </form:select> 
+5
source
 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}" /> 
0
source

Source: https://habr.com/ru/post/911327/


All Articles