我有一个List<String>
在im传递到视图的控制器。我需要用该数据填充<form:select>
。如何使用列表<String>填充<form:select>?
我试着将itemValue
属性设置为"name"
,但那不起作用。
我有一个List<String>
在im传递到视图的控制器。我需要用该数据填充<form:select>
。如何使用列表<String>填充<form:select>?
我试着将itemValue
属性设置为"name"
,但那不起作用。
你可以做到以下几点:
<form:select path="selectName">
<form:option value="0" label="Select an Option" />
<form:options items="${nameOfList}" />
</form:select>
通过提供唯一的项目属性窗体:选项标签,就应该使值和标签在你的列表中的每个字符串的值。
你也可以尝试如下:
<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);
}
然后
<form:select path="country" items="${countryList}" />
哪''这是? Spring MVC?无论哪种方式,向我们展示您的代码;我们无法通过简短的描述来猜测你正在做什么。 –
skaffman
2012-03-21 16:57:14
这不是JSTL。要了解JSTL是什么,请阅读http://stackoverflow.com/tags/jstl/info – BalusC 2012-03-21 17:00:36