Spring MVC dropdown box

♀尐吖头ヾ 提交于 2019-12-23 02:36:16

问题


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>

回答1:


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>


来源:https://stackoverflow.com/questions/11482993/spring-mvc-dropdown-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!