0

I cant display the image after uploading it. I have tried Display uploaded image in JSF ,ManagedBean return null to graphicImage in Primefaces ,Display database blob images in <p:graphicImage> inside <ui:repeat>. But cant find the problem

Here is my XHTML code

<p:fileUpload fileUploadListener="#{watermarkController.handleFileUpload}"
 update="img" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>

<p:graphicImage id="img" value="#{watermarkController.resultFile}"/>

And my bean

@ViewScoped
@Model
public class WatermarkController implements Serializable {

private static final long serialVersionUID = 8769727406867127721L;
private StreamedContent resultFile; 
// getter and setter

public void handleFileUpload(FileUploadEvent event) throws IOException {

    UploadedFile uploadedFile = (UploadedFile) event.getFile();

    InputStream input = null;

    try {
        input = uploadedFile.getInputstream();

        resultFile =new DefaultStreamedContent(input, "image/jpg");


    } catch (IOException e2) {

        e2.printStackTrace();
    } finally {
        input.close();
    }

}
Community
  • 1
  • 1
Tinus Jackson
  • 2,255
  • 1
  • 18
  • 47
  • 1
    Images are retrieved by sending a brand new request. This is covered at length [here](http://stackoverflow.com/a/12452144/1391249) (and [here](http://stackoverflow.com/a/10161878/1391249) too). Deliberately pay special attention to this, "*Images are not "inlined" in HTML output, but they are instead requested separately*". Besides, since you are using the `@Model` stereotype annotation which combines `@Named`, `@RequestScoped` in turn, there are redundant annotations on the managed bean, `@Named`, `@RequestScoped` and `@ViewScoped` which is something quite undesirable. – Tiny May 11 '15 at 13:03
  • I had the same issue, @SessionScoped worked for me. – Noor Nawaz May 11 '15 at 14:42
  • @Tiny Thanks for the comments i'm fairly new to all this . – Tinus Jackson May 12 '15 at 16:49

0 Answers0