By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,654 Members | 1,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,654 IT Pros & Developers. It's quick & easy.

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

P: 1
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.

Expand|Select|Wrap|Line Numbers
  1. public BufferedImage imageReturn(String taskId) throws IOException {
  2. byte[] bytes;
  3.  
  4. EntityManager em = (EntityManager) Component.getInstance("entityManager");
  5. System.out.println("Task ID : " + taskId);
  6.  
  7. bytes = (byte[]) em.createQuery("select t.image from Task t where t.taskId = " + taskId).getSingleResult();
  8.  
  9. System.out.println("bytes---> " + Arrays.toString(bytes));
  10. InputStream inputStream = new ByteArrayInputStream(bytes);
  11.  
  12. BufferedImage image = ImageIO.read(inputStream);
  13. return image;
In XHTML page :-

Expand|Select|Wrap|Line Numbers
  1. <tr> <td >
  2. Signature    
  3. </td> <td> <h:graphicImage id="image" alt="signature could not be found" value="#{taskHome.imageReturn(taskHome.instance.taskId)}" /> </td>
Thanks in advance :-)
Feb 27 '13 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
1.) Create a Servlet and map it's URL to /images/*.
2.) Use the servlet parameters or request.getPathInfo() 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
Expand|Select|Wrap|Line Numbers
  1. <h:graphicImage value="images/#{bean.imageId}"> 
where bean.getImageId returns the id of the image.
Mar 6 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Browse more Java Questions on Bytes