【发布时间】:2015-02-13 11:06:38
【问题描述】:
@Component
@Entity
@Table(name="menu")
@Configurable
public class Menu implements Serializable{
....
@OneToMany(mappedBy="menu", fetch=FetchType.EAGER)
private Set<VoceMenu> voceMenuList;
public Set<VoceMenu> getVoceMenuList() {
return voceMenuList;
}
public void setVoceMenuList(Set<VoceMenu> voceMenuList) {
this.voceMenuList = voceMenuList;
}
.....
}
我打印一个表单来编辑菜单及其相关的 VoceMenu 对象,这样:
<form:form action="editMenu" method="post" commandName="menu">
Menu id<form:input path="id" maxlength="11"/><br/>
......
<c:forEach items="${menu.voceMenuList}" varStatus="counter">
<form:input path="voceMenuList[${counter.index}].id" maxlength="11"/>
.....
</c:forEach>
<input type="submit">
</form:form>
但是,当我尝试保存对象菜单时,我得到了这个错误:
bean 类 [com.springgestioneerrori.model.Menu] 的无效属性“voceMenuList[0]”:不能 从大小为 0 的集合中获取索引为 0 的元素, 使用属性路径 'voceMenuList[0]' 访问
【问题讨论】:
-
请您发布您的控制器代码吗?
-
您的原始问题已得到解答。对于由完全独立的问题引起的任何后续问题,您应该提出一个新问题。
-
好的,谢谢你的帮助
标签: java spring jsp jstl spring-form