Struts 1 ActionForm 中的 ArrayList 未填充

发布于 2024-11-25 21:21:49 字数 3053 浏览 0 评论 0原文

我有一个 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>

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 ArrayLists. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘逸的'云 2024-12-02 21:21:49

getReasonData(int index)setReasonsData(ArrayListreasonsData) 更改为 getReqReas(....)setReqReas

Change your getReasonData(int index) and setReasonsData(ArrayList<RevisionReasonsTO> reasonsData) to getReqReas(....) and setReqReas

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文