【发布时间】:2014-11-04 09:05:49
【问题描述】:
我有下面的 FieldValue 模态类,带有 String 的 ArrayList 的 textValues 属性。
@Entity
@Table(name = "TBL_STD_FIELD_VALUE")
public class FieldValue implements Serializable {
@Id
@GeneratedValue
@Column(name = "FLD_VERSION")
private int version;
@Column(name = "FLD_VALUE")
private ArrayList<String> textValues;
public ArrayList<String> getTextValues() {
if(this.textValues == null){
return new ArrayList<String>();
}
return textValues;
}
}
下面是 addForm.jsp 。我正在将该 textValues 列表分配给输入字段,如下面的代码所示。
<form:form name="moduleForm" modelAttribute="fieldValue" id="moduleForm" action="/module/saveAddForm.htm" method="POST" onsubmit="return validateMandetoryFields();">
<table width="100%" id="preferenceTable" style="border: 0px solid #ccc;">
<c:forEach items="${fields}" var="field" varStatus="no">
<tr height="30px" bordercolor="#FFF" style="cursor: pointer;" title="Module Name">
<td width="60%" align="left">
<form:input type="${field.type}" style="width: 250px;" path="textValues[${no.index}]" title="Name of the Module" />
</td>
</tr>
</c:forEach>
Belos 是来自控制器的代码,我正在使用 MultiActionController。
public ModelAndView addForm(HttpServletRequest request,HttpServletResponse response) {
String moduleId = request.getParameter("moduleId");
Module module = moduleDao.get(Module.class,Long.parseLong(moduleId));
List<Fields> fields = fieldDao.getAllFields(Long.parseLong(moduleId));
ModelAndView model = new ModelAndView("admin/module/addForm");
model.addObject("fields",fields);
model.addObject("fieldValue",fieldValue);
return model;
}
它给了我下面的错误信息。
org.springframework.beans.InvalidPropertyException: Invalid property 'textValues[0]' of bean class [com.cloudcodes.gdirectory.model.module.FieldValue]: Index of out of bounds in property path 'textValues[0]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
请指导我解决此问题。
【问题讨论】:
-
您已将
private ArrayListList<String>放入您的代码中。试试ArrayList<String>。还是您的代码 sn-p 有错字? -
在你的控制器中,我们能看到你初始化
fieldValue的部分吗? -
FieldValue fieldValue = new FieldValue();这条线在控制器中。