I was hoping by reflection that my sub-object would be re-created
automatically. This was not the case.
I had to take all the attributes and recreate the sub-object in the
ActionClass and then attach it to the
parent class.
So the jsp code stays "clean" and struts-like
****************************************************************************
***********************
<logic:iterate name="materialForm" property="substances" id="substanceBean">
<tr>
<td class="table2"><html:text name="substanceBean" property="casNumber"
styleClass="input1"/></td>
<td class="table2"><html:text name="substanceBean"
property="substanceName" styleClass="input1"/></td>
</tr>
</logic:iterate>
****************************************************************************
***********************
But in the UpdateMaterialAction class, there's a bit of work:
****************************************************************************
***********************
//2. Grab request params from Bean. Use this same bean to
repopulate
MaterialBean myForm = (MaterialBean)form;
//3. Create the Material Object along w/ child Substances Objects
and
// then call business logic in EJB
try
{
BusinessFacadeHome bhome = this.getBusinessFacadeHome();
BusinessFacade facade = bhome.create();
//1. This is the parent object w/ parent attributes
Material m = new Material();
m.setMaterialID(myForm.getMaterialID());
m.setSupplierMaterialName(myForm.getSupplierMaterialName());
m.setNikeMaterialName(myForm.getNikeMaterialName());
m.setSupplierProductID(myForm.getSupplierProductID());
m.setNikeProductID(myForm.getNikeProductID());
m.setMaterialDescription(myForm.getMaterialDescription());
m.setFinalProductApplication(myForm.getFinalProductApplication());
m.setRemarks(myForm.getRemarks());
m.setMaterialStatus(myForm.getMaterialStatus());
m.setLastUserUpdate(myForm.getLastUserUpdate());
m.setConfirmingUser(myForm.getConfirmingUser());
if (myForm.getExceedsSubstanceLimit()) {
m.setExceedsSubstanceLimit("1"); }
else { m.setExceedsSubstanceLimit("0"); }
//2. Struts does not automatically re-create sub-objects for
you from the jsp-- this doesn't work
ArrayList list = myForm.getSubstances();
System.out.println("list.size(): " + list.size());
Iterator i = list.iterator();
while (i.hasNext())
{
Substance s = (Substance)i.next();
System.out.println("s.getCasNumber(): " + s.getCasNumber());
}
//3. So we have to reconstruct the sub-object and attach it to
the parent node-- this works.
String[] substanceNames =
request.getParameterValues("substanceName");
String[] casNumbers = request.getParameterValues("casNumber");
for (int j=0;j<substanceNames.length; j++)
{
System.out.println(substanceNames[j]);
System.out.println(casNumbers[j]);
Substance s = new Substance();
s.setCasNumber(casNumbers[j]);
s.setSubstanceName(substanceNames[j]);
m.addSubstance(s);
}
facade.updateMaterial(m);
//3.3 remove EJB
facade.remove();
}//end-try
catch (Exception e) { e.printStackTrace(); }
****************************************************************************
***********************
-----Original Message-----
From: Domen, Ken [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 07, 2002 3:14 PM
To: '[EMAIL PROTECTED]'
Subject: getting ArrayList elements as objects
I want to be able to get (after a submit) the values of the iterator
as an ArrayList of objects in the action class. Currently, substances is
an ArrayList in bean Material.
How do people achieve this? Or is there a work around?
<logic:iterate name="materialForm" property="substances" id="substances">
<tr>
<td class="table2"><html:text name="substances" property="casNumber"
styleClass="input1"/></td>
<td class="table2"><html:text name="substances"
property="substanceName" styleClass="input1"/></td>
</tr>
</logic:iterate>
--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>