Java 在jsp中将映射(键和值)绑定到spring表单

Java 在jsp中将映射(键和值)绑定到spring表单,java,forms,spring,jsp,binding,Java,Forms,Spring,Jsp,Binding,我有一门课是这样的: public class MyClass { private Map<String, String> properties = new HashMap<String, String>(); } 公共类MyClass{ 私有映射属性=新HashMap(); } 我需要一个表单,用户可以在属性映射中添加键值对。我在这里找到的所有答案都显示了如何使用已知的键输入值,使用: <form:input path="properties['key

我有一门课是这样的:

public class MyClass {
    private Map<String, String> properties = new HashMap<String, String>();
}
公共类MyClass{
私有映射属性=新HashMap();
}
我需要一个表单,用户可以在属性映射中添加键值对。我在这里找到的所有答案都显示了如何使用已知的键输入值,使用:

<form:input path="properties['keyName']" />

如何使密钥也可编辑?我有点像

<form:input path="properties.key" /><form:input path="properties.value" />

我得到了这个工作,不得不再次找到这个页面来提供我的答案

我正在动态地向我的
添加一个键和值映射,我的解决方案有一个键输入和一个单独的值输入。然后,我在键上注册了一个更改侦听器,以更新输入值上的
名称

对我来说,最困难的部分是JQuery没有访问动态添加的键/值元素的ID的权限。这意味着,如果映射已经填充,我可以毫无问题地使用JQuery,但是如果它是一个新条目,我会遇到问题,并且对值输入的ID进行搜索不会成功

为了解决这个问题,我必须遍历DOM以获得值输入。这是我的代码JSP代码

<c:forEach var="points" items="${configuration.pointsValueMap}" varStatus="index">
  <div class="col-xs-3 ">
    <label for="pointMap[${index.index}]">Type:</label>
    <input type="text" id="pointMap[${index.index}]" class="pointMap" value="${points.key}"> : 
  </div>
  <div class="col-xs-3 ">
    <label for="pointMap[${index.index}]-value">Value:</label>
    <input type="text" id="pointMap[${index.index}]-value" name="pointsValueMap[${points.key}]" value="${points.value}">
  </div>
</c:forEach>

有人知道这件事吗?我也陷入了类似的境地。
/**
 * Register a listener on the form to detect changing the map's key
 */
$('form').on('change', 'input.pointMap', function(){
    var content = $(this).val();
    var id = $(this).attr('id');
    // have to travel the DOM for added elements to be accessed.
    // JQuery does not have visibility to the IDs of added elements
    $(this).parent().next().children('input').attr('name', 'pointsValueMap['+content+']');
    // if you are not dynamically adding key/values then 
    // all fields are accessible by JQuery and you can update by:
    $('#'+id+'-value').attr('name', 'pointsValueMap['+content+']');
});