• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

empty table cells

 
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 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.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic