我有一个ActionForm
(RevisionActionForm),我从DB2填充并在页面上显示。此表单包含各种字段和一个包含其他几个类和ArrayList
的类。页面加载正常,一切都按照我的预期显示,但是当提交页面时,表单不再具有ArrayList
元素(所有其他字段都按预期加载)。我假设问题源于ArrayList
已构建的事实,但是没有存储要存储的值的元素。以下是相关的代码段(我省略了我认为无关紧要的内容以便减少这个帖子。)
JSP
<logic:notEmpty name="revisionBean" property="revisionData.reasonsData">
<div>
</div>
<div style="vertical-align: top; text-align: left; font-size: 15px">
<strong> 604 Information </strong>
</div>
<logic:iterate id="reqReas" name="revisionBean" property="revisionData.reasonsData" indexId="reqReasIdx">
<div>
<ao:text name="reqReas" property="reasonCodeId" indexed="true"
label="Reason Code ID ${reqReasIdx+1}: "
size="5" maxlength="5" disabled="true"/>
</div>
<div>
<ao:text name="reqReas" property="priorityOrNum" indexed="true"
label="Priority Or Num ${reqReasIdx+1}: "
size="2" maxlength="2" disabled="true"/>
</div>
</logic:iterate>
</logic:notEmpty>
的ActionForm
public class RevisionActionForm extends BaseActionForm{
/**
* Transfer object for the Revision information.
*/
private RevisionTO revisionData = new RevisionTO();
public RevisionActionForm() {
}
public RevisionTO getRevisionData(){
return revisionData;
}
public void setRevisionData(RevisionTO revisionData){
this.revisionData = revisionData;
}
}
RevisionTO(持有ArrayList)
public class RevisionTO implements Serializable {
private ArrayList<RevisionReasonsTO> reasonsData = new ArrayList<RevisionReasonsTO>();
public RevisionTO() {
}
public ArrayList<RevisionReasonsTO> getReasonsData() {
return reasonsData;
}
public RevisionReasonsTO getReasonData(int index) {
if (reasonsData == null) {
reasonsData = new ArrayList<RevisionReasonsTO>();
}
while (index >= reasonsData.size()) {
reasonsData.add(new RevisionReasonsTO());
}
return reasonsData.get(index);
}
public void setReasonsData(ArrayList<RevisionReasonsTO> reasonsData) {
this.reasonsData = reasonsData;
}
}
动作 公共类RevisionAction扩展了Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception{
ActionForward forward = new ActionForward();
HttpSession session = request.getSession(false);
RevisionActionForm revisionForm = (RevisionActionForm) form;
}
我一直在网上进行研究,并在上周进行了实验而没有成功。如果这很明显,我很抱歉,但我对Java有点生疏,对Struts来说是新手。任何和所有的帮助将不胜感激。
答案 0 :(得分:1)
将您的getReasonData(int index)
和setReasonsData(ArrayList<RevisionReasonsTO> reasonsData)
更改为getReqReas(....)
和setReqReas