Struts 1 ActionForm 中的 ArrayList 未填充
我有一个 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;
}
}
操作 public class RevisionAction extends 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 还很陌生。任何和所有的帮助将不胜感激。
I have an ActionForm
(RevisionActionForm) that I am populating from DB2 and displaying on a page. This form has various fields and a class that contains several other classes and ArrayList
s. The page loads fine and everything displays as I would expect, however when the page is submitted the form no longer has the ArrayList
elements (all other fields are loaded as expected). I am assuming that the problem stems from the fact that the ArrayList
is built, but no elements exist for the values to be stored in. The following are relevant code segments (I have omitted what I feel is irrelevant in order to reduce this post).
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 (Holds 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;
}
}
Action
public class RevisionAction extends 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;
}
I have been researching on the net and experimenting for the last week without success. I apologize if this is obvious but I am a bit rusty at Java and new to Struts. Any and all help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
getReasonData(int index)
和setReasonsData(ArrayListreasonsData)
更改为getReqReas(....)
和setReqReas
Change your
getReasonData(int index)
andsetReasonsData(ArrayList<RevisionReasonsTO> reasonsData)
togetReqReas(....)
andsetReqReas