我有下面的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'放在你的代碼中。嘗試'ArrayList '。或者你在代碼片段中有錯字嗎? –
ha9u63ar
2014-11-04 09:13:57
在你的控制器中是錯字 – RBP 2014-11-04 09:22:26
,我們可以看到你初始化'fieldValue'的部分嗎? – jcera 2014-11-04 14:42:26