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();
}
}