• 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

logic:iterate

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I'm new to Struts and would like to ask for someone's help explaining the behavior of the logic:iterate tag.
I used the logic:iterate tag to display the contents of an ArrayList which are objects that contain a Hashtable which I display using another logic:iterate tag. However, when I tried to view the source after displaying the page, the outer </logic:iterate> tag seemed to be ignored, both the outer logic:iterate and the inner logic:iterate tags terminated when it encountered the closing inner </logic:iterate> tag. I used Tomcat 4 for this.
Here is a snippet of my code:
Note: "timeRecords" is an attribute I set in my session.
<logic:notEmpty name="timeRecords">
<table border="4">
<th>
<bean:message key="timeRecord.date"/>
</th>
<th>
<bean:message key="timeRecord.timeIn"/>
</th>
<th>
<bean:message key="timeRecord.timeOut"/>
</th>
<th>
<bean:message key="timeRecord.timeIn"/>
</th>
<th>
<bean:message key="timeRecord.timeOut"/>
</th>
<th>
<bean:message key="timeRecord.timeIn"/>
</th>
<th>
<bean:message key="timeRecord.timeOut"/>
</th>
<th>
<bean:message key="timeRecord.totalWorkHours"/>
</th>
<logic:iterate id="timeData" name="timeRecords">
<tr>
<td>
<bean:write name="timeData" property="date"/>
</td>
<logic:iterate id="log" name="timeData" property="timeLogs"/>
<td>
<bean:write name="log" property="key"/>
</td>
<td>
<bean:write name="log" property="value"/>
</td>
</logic:iterate>
</tr>
</logic:iterate>
</table>
</logic:notEmpty>

Source after loading the page.
<snip>
<table border="4">
<th>
Date
</th>
<th>
Time In
</th>
<th>
Time Out
</th>
<th>
Time In
</th>
<th>
Time Out
</th>
<th>
Time In
</th>
<th>
Time Out
</th>
<th>
Total No. of Working Hours
</th>
<tr>
<td>
2004-04-20
</td>
<td>
18:00:00
</td>
<td>
22:00:00
</td> -----> a closing </tr> should have been found here
<tr>
<td>
2004-04-21
</td>
<td>
08:00:00
</td>
<td>
18:00:00
</td>
</tr>
</logic:iterate> -->This is the unparsed closing /logic:iterate
</table>
</body>
</html>

Any ideas as to what I am doing wrong?
Thank you very much.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The outer <logic:iterate> matches the first </logic:iterate>, which seems a bug in struts!
 
Leo Lim
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just solved the problem now, the inner logic:iterate contains a "/" at the end which makes it an invalid logic:iterate tag. Thus, when the server
renders the page, the outer logic:iterate treats the closing inner logic:iterate as its closing tag instead of the outer logic:iterate tag which is why the outer logic:iterate tag is ignored and the closing </tr> is ignored as well as the outer loop reiterates as it encounters the inner logic:iterate tag.
Thanks for all the help though.
<logic:iterate id="timeData" name="timeRecords">
<tr>
<td>
<bean:write name="timeData" property="date"/>
</td>
<logic:iterate id="log" name="timeData" property="timeLogs"/>
^^^^
<td>
<bean:write name="log" property="key"/>
</td>
<td>
<bean:write name="log" property="value"/>
</td>
</logic:iterate>
</tr>
</logic:iterate>
 
reply
    Bookmark Topic Watch Topic
  • New Topic