我一直在试图找出如何创建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>