Reputation: 11
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.
Upvotes: 1
Views: 2996
Reputation: 11
Change your getReasonData(int index)
and setReasonsData(ArrayList<RevisionReasonsTO> reasonsData)
to getReqReas(....)
and setReqReas
Upvotes: 1