Reputation: 2092
I have been trying to find out how to create a dropdown box in Spring MVC. Here is my controller:
@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";
}
and here is the jsp page:
<%@ 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}" />
Actual output:
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)
...
Expected output:
<select id="dataVis" name="dataVis">
<option value="pie">Pie Chart</option>
<option value="categorizedVertical">Column Chart</option>
</select>
Upvotes: 1
Views: 2700
Reputation: 3194
Have you tried doing something like this?
<form:select path="dataVisArray"><br />
<form:option label="Select..." value=""/>
<form:options items="${dataVisArray} itemLabel="label" itemValue="value"/>
</form:select>
Upvotes: 2