2011-07-20 75 views
1

我有一個ActionForm(RevisionActionForm),我從DB2中填充並顯示在頁面上。這種形式有不同的領域和類別,其中包含幾個其他類和ArrayList s。頁面加載正常,所有內容都按我的預期顯示,但是當提交頁面時,表單不再有ArrayList元素(所有其他字段按預期加載)。我假設這個問題源於ArrayList這個事實,但是沒有要存儲的值的元素。下面是相關的代碼段(爲了減少這篇文章,我忽略了我認爲不相關的東西) 。Struts 1中的ArrayList ActionForm未被填充

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

行動 公共類RevisionAction延伸行動{

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中有點生疏。任何和所有的幫助,將不勝感激。

回答

1

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