我一直在尝试找出如何在 Spring MVC 中创建一个下拉框。这是我的控制器:
@ResourceMapping(value = "availableDataVis")
public String getAvailableDataVis(Model model,
@RequestParam("widgetId") String widgetId) {
HashMap<String,Map<String,String>> hashMapOfDataVis = new HashMap<String,Map<String,String>>();
Map<String,String> m = new LinkedHashMap<String,String>();
m.put("pie", "Pie Chart");
m.put("categorizedVertical", "Column Chart");
hashMapOfDataVis.put("m", m);
if (hashMapOfDataVis.containsKey(widgetId))
{
model.addAttribute("dataVisArray", hashMapOfDataVis.get(widgetId));
}
return "selDataVisComboBox";
}
这是jsp页面:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<form:select path="dataVisArray" items="${dataVisArray}" />
实际输出:
ERROR
Cause: javax.portlet.PortletException: org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'dataVisArray' available as request attribute
Message: org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'dataVisArray' available as request attribute
StackTrace:
javax.portlet.PortletException: org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'dataVisArray' available as request attribute
at org.jboss.portal.portlet.impl.jsr168.api.PortletRequestDispatcherImpl.dispatch(PortletRequestDispatcherImpl.java:169)
at org.jboss.portal.portlet.impl.jsr168.api.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:84)
...
预期输出:
<select id="dataVis" name="dataVis">
<option value="pie">Pie Chart</option>
<option value="categorizedVertical">Column Chart</option>
</select>