• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

nested logic:iterate

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In our application we have action classes like this:

class TaskActionForm
+String taskId
+String taskName
+ArrayList subTasks

The ArrayList 'subTasks' contains SubTaskActionForm instances

class SubTaskActionForm
+String subTaskId
+String subTaskName

The JSP gets an ArrayList of TaskActionForms. My objective is to iterate through the ArrayList to print the task details. If a task has subtasks then I need to get the ArrayList of subtasks and print them too.

I am new to struts and am confused on how to achieve this with nested <logic:iterate>. Can someone help me? Thanks.
 
raamam
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey.. I have managed to do it. I am posting it here for the benefit of newbies like me:


<table>
<logic:iterate id="TaskVar" name="AttributeKey" type="TaskActionForm">
<tr>
<td><bean:write name="TaskVar" property="taskId" />
<td><bean:write name="TaskVar" property="taskName" />
</tr>
<logic:iterate id="subTaskVar" name="TaskVar" property="subTasks" >
<tr>
<td><bean:write name="TaskVar" property="subTaskId" />
<td><bean:write name="TaskVar" property="subTaskName" />
</tr>
</logic:iterate>
</logic:iterate>
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also try nested:iterate tag, then you can skip the name attribute and just have property attribute; this will work if you either have nested:form or nested:root tag for you top level bean.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

raamam wrote:Hey.. I have managed to do it. I am posting it here for the benefit of newbies like me:


<table>
<logic:iterate id="TaskVar" name="AttributeKey" type="TaskActionForm">
<tr>
<td><bean:write name="TaskVar" property="taskId" />
<td><bean:write name="TaskVar" property="taskName" />
</tr>
<logic:iterate id="subTaskVar" name="TaskVar" property="subTasks" >
<tr>
<td><bean:write name="TaskVar" property="subTaskId" />
<td><bean:write name="TaskVar" property="subTaskName" />
</tr>
</logic:iterate>
</logic:iterate>



Thanks, you saved my life
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic