0

I'm uploading images using <p:fileUpload> as follows.

<p:fileUpload mode="advanced"
              fileLimit="1"
              allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
              update="@this"
              fileUploadListener="#{bean.fileUploadListener}"/>

The listener method in the associated JSF managed bean.

private byte[] file; //Getter only

public void fileUploadListener(FileUploadEvent event) throws IOException {
    UploadedFile uploadedFile = event.getFile();
    file = IOUtils.toByteArray(uploadedFile.getInputstream());
}

How to display this uploaded image file on <p:graphicImage> directly from this JSF managed bean after it has been uploaded? It is just to prompt a user that the image being previewed is going to be uploaded.

Tiny
  • 24,933
  • 92
  • 299
  • 571
  • Take a look here http://stackoverflow.com/questions/11506762/display-uploaded-image-in-jsf or here http://stackoverflow.com/questions/4459379/preview-an-image-before-it-is-uploaded?lq=1 – Emil Kaminski Jul 22 '14 at 07:28
  • Do you still need help with that ? The second method (client side javascript) posted by Emil Kaminski will save you a lot of bandwidth and electricity, so money ;) –  Jul 22 '14 at 18:05
  • The image is to be displayed for a preview on another tab (`` of ``). Uploading and previewing of an image is on separate tabs. Therefore, I need a session scoped managed bean to get hold of the image. The client side solution is unlikely to work. – Tiny Jul 23 '14 at 01:12

0 Answers0