【问题标题】:Spring form binding to Set inside c:forEachSpring 表单绑定到 c:forEach 内的 Set
【发布时间】:2011-11-08 21:51:01
【问题描述】:

我正在使用 Spring form 标记库在我的 JSP 中进行表单绑定。我的命令对象包含一个 Set,我想使用 JSTL <c:forEach> 迭代该集合,并为我的集合中的每个对象创建一个 Spring <form:input>。我已经看到如何使用List

<form:form>
  <c:forEach items="${itemList}" var="item" varStatus="status" >
    <form:input path="itemList[${status.index}].name" />
  </c:forEach>
</form:form>

我的问题是我使用的是无序的Set,我不相信我可以使用index 属性。将Set 的内容添加到 Spring 绑定表单的最佳实践是什么?我想我只需要转换为List,但我对任何可能的替代方案都很感兴趣。

【问题讨论】:

  • 就我而言,我必须从 jsp 页面获取列表中每个用户的已检查属性,因此我必须在表单支持对象中使用该列表,有人可以帮助我吗那,这是我的问题的链接stackoverflow.com/q/11478816/1458508
  • 以上 JSP 代码在 Websphere 中不起作用,出现以下错误。 org.springframework.beans.NotReadablePropertyException: Invalid property 'xxxx[0]' of bean class [com.xxx.yyy.conf.xxxx]: Bean property 'xxxx[0]' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
  • 在 Websphere 7 应用服务器中有人对此有疑问吗?

标签: java data-binding spring-mvc jstl


【解决方案1】:

你的表单支持对象应该在List 中包含这些数据,真的。迭代集合没有多大意义,因为不能保证迭代顺序意味着任何东西——当然,集合没有index 的概念。我想您可能对这些元素在页面上出现有一定的期望顺序。

【讨论】:

  • 这确实有道理。谢谢你的回答。
猜你喜欢
  • 1970-01-01
  • 2016-11-30
  • 1970-01-01
  • 1970-01-01
  • 2012-10-31
  • 1970-01-01
  • 1970-01-01
  • 2015-02-01
  • 2017-05-25
相关资源
最近更新 更多