Spring MVC下拉框

时间:2012-07-14 10:29:26

标签: spring jsp spring-mvc jsp-tags

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

1 个答案:

答案 0 :(得分:2)

你尝试过这样的事吗?

<form:select path="dataVisArray"><br />
     <form:option label="Select..." value=""/>
     <form:options items="${dataVisArray} itemLabel="label" itemValue="value"/>
</form:select>