Hi all-
I finally solved my iterate problem. It was a learning experience, and very
time consuming. Hence here is the distilled version briefly.
We have an "Invoice" business object (what a fancy name for a plain "bean")
with a member "invoiceLineItems" of type Hashtable. It has static methods to
instantiate a "Invoice" object from db and public method to save itself to
db. It has no knowledge of it's "container" which is a servlet engine this
time.
We have an "invoiceForm" view object of type "InvoiceForm", which in return
is an ActionForm, with a member property "invoice" of type "Invoice". In the
default constructor of "InvoiceForm", an "Invoice" is instantiated and
assigned to "invoice" member.
We have a "invoice.jsp" that refers to "InvoiceForm"'s elemets as follows:
<html:text property="invoice.aProperty" size="16" maxlength="16"/>
The individual "InvoiceLineItem"s stored in
invoiceForm->invoice->invoiceLineItems are referred as follows:
<logic:iterate name="invoiceForm" property="invoice.invoiceLineItems"
id="lineItemAsEntry"> //this only returns an Map.Entry, where's
introspection?
<bean:define id="lineItem" name="lineItemAsEntry" property="value"
type="InvoiceLineItem"/> //now we cast
<bean:write name="lineItem" property="aLineItemProperty"/> //finally we
have an InvoiceLineItem!
</p>
</logic:iterate>
So, I had to cast the individual Hashtable entries to type InvoiceLineItem
to be able to access its properties. Even after so, there is one problem
remained. I got back the elements in the wrong order. It iterated like
3-1-2, 1 being the first element I put into the hashtable.
I hope I shed some light into the infamous "iteration" problem. I thank Adam
for the generous help which helped me tackle it from a different angle.
--a
PS. Also, don't forget to put <%@ taglib uri="/WEB-INF/struts-logic.tld"
prefix="logic" %> at the beginning of the page.