Web tier: servlets, JSP, Web frameworks: Best way to use BLOB's in JSF's

  1. Best way to use BLOB's in JSF's (1 messages)

    I am using BLOB's wiht CMP's. The CMP maps the BLOB to
    a byte array. My DTO has the following properties.

     private String name;
     private byte[] poster;
     Is there a way to directly display this in a datatable wihtout first saving it in a .gif file and then
    displaying it as a graphic image in JSF's or is there a better way to do it.

    Threaded Messages (1)

  2. Blob in JSF[ Go to top ]

    I don't think we can use byte[] array to show images in JSF. But there is a way to avoid that temporary image file. What you have to do is create a servlet, which will read the blob and write to the ServletOutputStream. Then in your JSF page put an iframe, where you want to show the image. src attribute of this iframe will point to ImageServlet. You JSF page will look like: ImageServlet's doGet method will be like: res.setContentType("image/gif"); ServletOutputStream out = res.getOutputStream(); dao = new EmployeeImageDAO(); dao.openConnection(); InputStream in = dao.getEmployeeImageStream(Integer.parseInt(empId)); byte[] buffer = new byte[in.available()]; while(in.read(buffer) != -1) { out.write(buffer); } out.flush();