How to use c:forEach to retrieve properties from an ArrayList of JavaBeans
Posted on 2004-04-12
From a jsp page, I am using jsp:setProperty to set a String property in a parent bean. The property value is then used as a parameter to a SQL query. After the query runs, the parent bean instantiates a child bean for each row of the resultset and sets the returned resultset values into the child bean properties. Each bean is added to an ArrayList which is a property of the parent. There is a getter which returns this ArrayList. Each child also has appropriate getters for its properties. I have tested that the parent correctly creates the ArrayList of children by using a separate Java class to instantiate the parent and access the properties of its children.
I can successfully set and get the parent's String property from my jsp page, but cannot figure out how to iterate over the ArrayList of child beans using c:forEach. My goal is to build a table to show the child bean property values. It seems to me it all boils down to a simple collection of objects whose properties I want to access -- something that I thought forEach could do. Is this possible? If so, how? An example would be really helpful.
Thanks in advance for any insight into this.