【问题标题】:spring mvc, form:select not workingspring mvc,表单:选择不起作用
【发布时间】:2013-09-17 17:38:30
【问题描述】:

我在将某些字段绑定到表单时遇到问题。 我的例子(对不起代码中的错误——我是从头开始写的) 问题是: 我可以绑定表单:从类中选择 - 我的数据有 Map 吗? JSP页面不渲染下拉列表...其他字段被渲染(例如:input type="text")

    Class FormDocument
    {
    private Map<Integer, String> docsMap;

    public Map<Integer, String> getDocsMap()
        {
        this.docsMap = new HashMap<Integer, String> ();
        this.docs.put(1, “Document01”);
        this.docs.put(2, “Document02”);
        this.docs.put(3, “Document03”);

        return docsMap;
        }

        // other setter, getters
    }

jsp“formPage.jsp”:

    <form:form >
    <form:select path=”docsMap” items=”docsMap” />
    </form:form>

控制器:

    @RequestMapping(“/formShow”)
    public String getFormPage(Model model)
    {
    model.addAttribute(“command”, new FormDocument());

    return “formPage”;
    }

如果我在控制器中添加行: model.addAtribute("docsMap", AND HERE IS Map); 它会呈现我的选择框...

【问题讨论】:

  • path 是 FormDocument 中的属性。 items 是要渲染的项目列表,基本上是所有可选项目的集合。

标签: spring select combobox bind


【解决方案1】:

也许这篇关于 Spring 数据绑定的教程会有所帮助:

http://howtoprogramwithjava.com/session35

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-24
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    • 2014-06-09
    • 1970-01-01
    相关资源
    最近更新 更多