Re: How to display a Blob (byte[]) from database in a Tapestry template

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Re: How to display a Blob (byte[]) from database in a Tapestry template

Thank you for your help.  I corrected those two oversights, and got the
class working successfully by changing the onActivate() parameter from
byte[] to 'User' (code below).  The image now displays, but I wonder if
when passing a 'User' object Tapestry passes just the id as reference
(using Tapestry-Hibernate ValueEncoder), or whether I ought to explicitly
pass the id like so: user.getId().

Also, Welcome.tml will untimately display several images from the
database, of different entity types and multiple instances.  I'm wondering
how BlobImage.class might be called numerous times from the same template.

Finally, I tried your shorter alternative: "return
"data:image/png;base64," +
Base64.getUrlEncoder().encodeToString(user.getImage());".  It didn't work;
the compiler seemed to point to the Java version (I use 1.8).



package com.example.harbour.pages;

import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.annotations.Property;

import com.example.harbour.entities.User;


 * Class created for displaying Blob (profile) images read from the
database, as per the below howto:
public class BlobImage {

    private User user;

    public StreamResponse onActivate(User user){

        this.user = user;

        //Retrieve your image using the context parameter(s)
        final InputStream imageStream = new

        return new StreamResponse(){

            public InputStream getStream() throws IOException {
                return imageStream;

            public String getContentType(){
                return "image/png";

            public void prepareResponse(Response response){}

To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

"A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away." - Antoine de Saint-Exupéry.