gpt4 book ai didi

java - Struts 1 ActionForm 中的 ArrayList 未填充

转载 作者:太空宇宙 更新时间:2023-11-04 08:34:14 25 4
gpt4 key购买 nike

我有一个 ActionForm (RevisionActionForm),我从 DB2 填充它并显示在页面上。该表单具有各种字段和一个包含其他几个类和 ArrayList 的类。页面加载正常,所有内容都按我的预期显示,但是当提交页面时,表单不再具有 ArrayList 元素(所有其他字段都按预期加载)。我假设问题源于以下事实:ArrayList 已构建,但不存在用于存储值的元素。以下是相关代码段(为了减少这篇文章,我省略了我认为不相关的代码段)。

JSP

<logic:notEmpty name="revisionBean" property="revisionData.reasonsData">
<div>
&nbsp;
</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>

Action 表单

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;
}
}

行动 公共(public)类 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 还很陌生。任何和所有帮助将不胜感激。

最佳答案

更改您的 getReasonData(int index)setReasonsData(ArrayList<RevisionReasonsTO> reasonsData)getReqReas(....)setReqReas

关于java - Struts 1 ActionForm 中的 ArrayList 未填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6766687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com