Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

empty table cells

 
Leo Lim
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a hashtable containing timeIn, timeOut logs for an attendance system. I place a column, total no. of hours at the end of the table, however, there are times when the logs are incomplete that is, there
is only one timeIn, timeOut pair for a specific day. So I have to add
the nbsp; in my table cells so that the data for the total no. of hours
will fall under the total no. of hours table and not on the second time in
column.

Sample table
Time In Time Out Time In Time Out Time In Time Out Total Hours
7:00 18:00 3.0
---------------------------------------------------------------------------

Is there an elegant way to do this using the logic:iterate tag?

My code to do this is as follows:
<logic:iterate id="timeData" name="timeRecords">
<tr>
<logic:iterate id="log" name="timeData" property="timeLogs">
<td align="center" bgcolor="#FFFFFF" height="1" width="94">
<bean:write name="log" property="key"/>
</td>
<td align="center" bgcolor="#FFFFFF" height="1" width="94">
<bean:write name="log" property="value" />
</td>
</logic:iterate>
<!-- add a logic:iterate here to iterate over the empty table cells
-->
<td align="center" bgcolor="#FFFFFF" height="1" width="94">
<bean:write name="timeData" property="totalWorkTime"/>
</td>
</tr>
</logic:iterate>

I assumed that each entry is complete and there are no blank entries. I've thought of adding an offset variable in my bean so that I can add the nbsp; for the empty table cells accordingly but I find this to be too cumbersome. Any ideas on how to fill those empty cells using logic:iterate? The problem I encountered when I tried using logic:iterate to fill in the blank cells is that logic:iterate needs a collection to iterate over, in this case, no collection is obviously needed, it just needs to iterate over the parts where there are no time log entries.

Thank you very much.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as the headers (such as Time In) belong to the same table as your values, you should not have any spacing issues.   is not necessary.

And you can take care of the td empty cell issue with:

<logic:iterate id="timeData" name="timeRecords">
<% int count = 3; // Assumes three Time In/Time Out pairs %>
<tr>
<logic:iterate id="log" name="timeData" property="timeLogs">
<td align="center" bgcolor="#FFFFFF" height="1" width="94">
<bean:write name="log" property="key"/>
</td>
<% count--; %>
<td align="center" bgcolor="#FFFFFF" height="1" width="94">
<bean:write name="log" property="value" />
</td>
</logic:iterate>
<% if(count-- > 0 ){ %>
<td></td>
<% } %>
<td align="center" bgcolor="#FFFFFF" height="1" width="94">
<bean:write name="timeData" property="totalWorkTime"/>
</td>
</tr>
</logic:iterate>

Best of luck!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic