aspose file tools
The moose likes Struts and the fly likes empty table cells Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Struts
Reply Bookmark "empty table cells" Watch "empty table cells" New topic
Author

empty table cells

Leo Lim
Greenhorn

Joined: Apr 25, 2004
Posts: 5
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

Joined: Feb 05, 2003
Posts: 4695

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!


A good workman is known by his tools.
 
 
subject: empty table cells
 
Threads others viewed
Help me about html:select
logic:iterate
Show - Hide Functionality
getting value in logic iterate
Html to database
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture