views:

73

answers:

1

Both of the following JSTL checks return positive - resulting in the inner message being displayed ("image not null"/"image not empty") - even when the current record does not have an image associated with it.

<c:if test="${rec.imgdata != null}">image not null</c:if>

<c:if test="${not empty rec.imgdata}">image not empty</c:if>

The image is stored as a Blob for each record. What's the correct way to check whether the Blob (rec.imgdata) is non-empty?

+2  A: 

I wouldn't use Blob in JSTL. I'd verify beforehand whether the blob is not empty by calling length(), and then set the value as request attribute. I.e.:

request.setAttribute("showImage", rec.getImgData().length() > 0);

if you have more than one rec then create a new property imageAvailable and call rec.setImageAvailable(rec.getImgData().length() > 0)

Have in mind that you can't stream the page AND the image in one response. You only set the path to the image. Which will be a new servlet which will in turn load thh Blob and stream it to the client.

Bozho
I already have a servlet that displays the images. But I need to know whether to call that servlet or display a holder image if the blob is empty. It's easier to do the check in the JSTL than in a controller or model because it's a list of records and I don't want to manage a separate record to indicate the presence of absence of image data.
Egg Yolk
then the first part of my answer should be fine.
Bozho