JSP form:checkbox into a c:foreach

眉间皱痕 提交于 2019-12-06 09:19:28

This problem is strangely undocumented on most places. Here is an extract from the links I am posting below. The gist is that we need a static placeholder which maps to the type instead of the value of the bean. So anything inside a ${} will not work out. For this, and in the specific case of using a JSTL loop operator <c:forEach> with s[ring form tld, we should refer to the type information in each iteration using the varStatus attribute of the <c:forEach> operator, just like indices of an array, and thus refer to the inner properties of the iterable collection using . on the collection variable accessible via the outermost bean backing up the form.

For example:

<c:forEach items="${teamslist_session.teams}" var="team" varStatus="teamsLoop">
<form:input path="teams[${teamsLoop.index}].name"/>
</c:forEach>

where:

  • teamList_session is the bean backing up the form
  • teams is the collection of beans the properties of which we need to set in the path attribute
  • var is the a reference to each member of the teams collection
  • teamsLoop is the iteration index, which is used in the line below to refer to the say, ith element's bean's property called name

Please refer to the following links for more information: Forum Discussion - See the last post The link provided for reference in link 1

This Link can be useful to you. Thanks

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