I have a method which returns 'image' and I need to display the same image in UI

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • srikanthneel
    New Member
    • Feb 2013
    • 1

    I have a method which returns 'image' and I need to display the same image in UI

    Hi i have a method which returns 'image' and i need to display the same image in UI and am using jsf1.2 , icefaces 1.8.2 , Jboss seam.
    Am adding the snippet i used to display image in UI, but am unable to get image in UI.

    Code:
    public BufferedImage imageReturn(String taskId) throws IOException {
    byte[] bytes;
    
    EntityManager em = (EntityManager) Component.getInstance("entityManager");
    System.out.println("Task ID : " + taskId);
    
    bytes = (byte[]) em.createQuery("select t.image from Task t where t.taskId = " + taskId).getSingleResult();
    
    System.out.println("bytes---> " + Arrays.toString(bytes));
    InputStream inputStream = new ByteArrayInputStream(bytes);
    
    BufferedImage image = ImageIO.read(inputStream);
    return image;
    In XHTML page :-

    Code:
    <tr> <td >
    Signature	
    </td> <td> <h:graphicImage id="image" alt="signature could not be found" value="#{taskHome.imageReturn(taskHome.instance.taskId)}" /> </td>
    Thanks in advance :-)
    Last edited by Rabbit; Feb 27 '13, 04:48 PM. Reason: Please use code tags when posting code.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    1.) Create a Servlet and map it's URL to /images/*.
    2.) Use the servlet parameters or request.getPath Info() to get an image id and use that id in the servlet to stream out the image data
    3.) Make your graphicImage tag point to your image id e.g
    Code:
    <h:graphicImage value="images/#{bean.imageId}">
    where bean.getImageId returns the id of the image.

    Comment

    Working...