JSP : No Borders for empty data cells

D

Dave Ortman

I'm sure this has got to be a simple problem to get around, but for some
reason the simple solution is eluding me. :(

I have a JSP page that's simply showing data. I fetch the data from the
database, place it in a few beans, then pass that to a JSP page which
displays the data in a few tables. Some of the fields queried from the
database are empty, so I'm returning empty strings. The result is that the
border for the table is not being drawn, as the cell is empty.

None of the ideas of getting around this seemed ideal:

1. Pad each table cell with a " " (in addition to whatever JSP tags are
in that cell). That way, if nothing is returned from the JSP tag, the cell
still has some content.

2. Manually place the " " in the bean when I'm querying the
database.... that's not right.

3. Write a JSP filter to located empty table cells and insert a " ".
That seems heavy handed.

4. Make each JSP tag an if statement that checks the length of the value
it's displaying. If it's zero, then write " " instead of the bean
value.

None of these seem ideal. Does anyone have the simply solution, which I
must be overlooking?

Thanks,
-Dave
 
A

Adam Maass

Dave Ortman said:
I'm sure this has got to be a simple problem to get around, but for some
reason the simple solution is eluding me. :(

I have a JSP page that's simply showing data. I fetch the data from the
database, place it in a few beans, then pass that to a JSP page which
displays the data in a few tables. Some of the fields queried from the
database are empty, so I'm returning empty strings. The result is that the
border for the table is not being drawn, as the cell is empty.

None of the ideas of getting around this seemed ideal:

1. Pad each table cell with a " " (in addition to whatever JSP tags are
in that cell). That way, if nothing is returned from the JSP tag, the cell
still has some content.

2. Manually place the " " in the bean when I'm querying the
database.... that's not right.

3. Write a JSP filter to located empty table cells and insert a " ".
That seems heavy handed.

4. Make each JSP tag an if statement that checks the length of the value
it's displaying. If it's zero, then write " " instead of the bean
value.

None of these seem ideal. Does anyone have the simply solution, which I
must be overlooking?

Note that this is not a Java (or even JSP) problem, but a problem with HTML.
The HTML books I have say that empty cells do not get borders in most
browsers. And that the way to force a border into an otherwise empty cell is
to print a   into the cell.

Solution #1 might be a quick fix, but will undoubtedly raise some subtle
display issues later. (Why do some rows of the table take more vertical
space than necessary?)

Solution #2 is not the way to manage the issue, since the problem occurs
only in at the View-level. Don't fix View-level issues in the Model or the
Controller.

Solution #3, is, agreed, heavy-handed and will burden your app with lots of
unnecessary parsing. It'll really put a damper on performance.


Solution #4 is the way to go. And this is a perfect place for the ternary
operator:

Rather than:

if("".equals(str))
return " ";
else
return str;

write:

return "".equals(str) ? "nbsp;" : str;


-- Adam Maass
 
S

Scott Yanoff

Dave said:
displays the data in a few tables. Some of the fields queried from the
database are empty, so I'm returning empty strings. The result is that the
border for the table is not being drawn, as the cell is empty.

None of the ideas of getting around this seemed ideal:

1. Pad each table cell with a " " (in addition to whatever JSP tags are
in that cell). That way, if nothing is returned from the JSP tag, the cell
still has some content.

That's acceptable for an Intranet or something where you are not
displaying data to external customers. However, better solutions exist.
2. Manually place the " " in the bean when I'm querying the
database.... that's not right.

I agree. It is better to let the "view" or presentation layer deal with
this and let the bean deal with non-presentation things.
4. Make each JSP tag an if statement that checks the length of the value
it's displaying. If it's zero, then write " " instead of the bean
value.

I think that this is acceptable since you are dealing with it in the
presentation layer.

Another option is to do away with borders completely and just color the
backgrounds of the table cells a light color. You could use a
stylesheet for this to ensure that the table cells always have a
background color.

One other option might be to have the bean return "--" or "N/A" when
there is no data but I don't know if that is acceptable for you and what
it will do to your presentation.

Good luck,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top