Link to home
Start Free TrialLog in
Avatar of noijet
noijet

asked on

How to use <logic:iterate> strut tag to loop arrayList that holds other arrayList

Hi, I set in request “arrayListParent” that holds a couple of “arrayListChildren.  I know how to loop through one arraylist using <logic:iterate>, but in this case, I have an arraylist holding other arrayList.  I have pasted my current jsp code on the bottom that uses scripting to display the arraylist and it’s children, that works fine.  But can anyone provide me an example to do that using controls like code directly below here?
Thanks so much for your help,
noijet
 ********* Version with jsp tag controls *******
<logic:iterate id="courses" name="arrayListParent" scope="request"
        type="java.util.ArrayList">    
            ……..//Have no idea how to get arrayListChildren            
</logic:iterate>    
************** Current version in JSP*********
    <%    
    ArrayList arrayListParent = (ArrayList)request.getAttribute( “arrayListParent”);
    ArrayList attendees = new ArrayList();
    Iterator iterator = arrayListParent.iterator();
    Attendee attendee = new Attendee();        
      for (int i = 0; iterator.hasNext();i++) {
          attendees = (ArrayList)iterator.next();
          Iterator iterator2 = attendees.iterator();
          for(int j = 0; iterator2.hasNext();i++) {
              attendee = (Attendee)iterator2.next();              
              %><%= attendee.getLastName()%>,<%=attendee.getFirstName()%>              
              <%              
          }
    }    
    %>

SOLUTION
Avatar of Jaax
Jaax
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of noijet
noijet

ASKER

Hi Jaax, thanks for your reply:
  Reading that message: I can do:
<logic:iterate id="parent" name="arrayListParent" scope="request"
        type="java.util.ArrayList">    
           <logic:iterate id="child" name="arrayListChildren"   type="java.util.ArrayList">
                  <bean:define name="child" property="firstname"/> ,  
                  <bean:define name="child" property="firstname"/>  
          </logic:iterate>
</logic:iterate>    
***My question is "arrayListChildren" holds a list of objects of type Child that has properties firstname and lastname, the above code would work right?

Thanks,
noijet
Avatar of Manish
Inside it, again use logic iterate tag.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of noijet

ASKER

Hi all, I will try out suggestions and get back you you!

Thanks again,
noijet