简体   繁体   English

<form:options tag spring mvc binding

[英]<form:options tag spring mvc binding

I am binding a list with Spring MVC form select box like this given below 我将列表与Spring MVC表单选择框绑定在一起,如下所示

<c:forEach var="item" items="${instance.parameters}" varStatus="itemsRow">
    <form:select size="6" path="parameters[${itemsRow.index}].parmvalues" multiple="true">

        <form:options items="${item.pluginParmvalues}" itemValue="id" itemLabel="parmValue" />

    </form:select>
</c:forEach>

After binding this <form:select displays values correctly. 绑定此<form:select正确显示值。 But when I try to save it it throws exception. 但是当我尝试保存它时会抛出异常。 Should I also bind <form:options values to something like this 我还应该将<form:options值绑定到这样的东西吗

<form:options path="parameters[${itemsRow.index}].parmvalues[0].parmValue"

instead of items="${item.pluginParmvalues}" to get/save values in controller? 而不是items="${item.pluginParmvalues}"来获取/保存控制器中的值?

Exception: 例外:

Cannot convert value of type [java.lang.String] to required type [com.domain.Parmvalue] for property 'parmvalues[0]': no matching editors or conversion strategy found] 无法将属性“ parmvalues [0]”的类型[java.lang.String]的值转换为必需的类型[com.domain.Parmvalue]:找不到匹配的编辑器或转换策略]

This way select box is not being bounded. 这种选择框不受限制。 You have to take a hidden field and bind that hidden field with path="parameters[${itemsRow.index}].parmvalues" . 您必须获取一个隐藏字段,并将该隐藏字段与path="parameters[${itemsRow.index}].parmvalues" Each time select box value is changed. 每次更改选择框的值。 Change value of that hidden field too through javascript/jquery. 也可以通过javascript / jquery更改该隐藏字段的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM