Ali,
You are getting the InvoiceLineItems out of order b/c you are storing them
in a Map or Hashtable. These collections do not preserve the order of the
objects as they are inserted into them. If you want to preserve the
ordering, you need to use a Collection that implements the List interface
(ArrayList, LinkedList) You could use a TreeMap or SortedMap, but these
would incur more overhead for your application than using a collection that
implements the List interface.
-Richard
At 01:52 AM 9/23/01 -0400, you wrote:
>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:
>
>The individual "InvoiceLineItem"s stored in
>invoiceForm->invoice->invoiceLineItems are referred as follows: //this
>only returns an Map.Entry, where's introspection? //now we cast //finally
>we have an InvoiceLineItem!
>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.