wood burning stoves*
The moose likes Struts and the fly likes nested logic:iterate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "nested logic:iterate" Watch "nested logic:iterate" New topic
Author

nested logic:iterate

raamam
Greenhorn

Joined: Aug 06, 2003
Posts: 4
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

Joined: Aug 06, 2003
Posts: 4
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>
Masha Klimenko
Ranch Hand

Joined: Feb 04, 2004
Posts: 31
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.


SCJP
Wriju Bharadwaj
Greenhorn

Joined: Aug 06, 2008
Posts: 1
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: nested logic:iterate