Hello,
I am new newbie of primefaces. I want to upload a photo and preview. The following are my code:
xhtml:
<TD><p:fileUpload width="63" image="/design/browserBtn.JPG"widgetVar="pis08Uploader" auto="true"
update="form:seriesPhoto" cache="false" fileUploadListener="#{formBeanPIS08.handleUploadSeriesPhoto}"
allowTypes="*.png;" description="Images (*.png)" sizeLimit="1000000"/> </TD>
<TD><p:graphicImage id="seriesPhoto" cache="false" value="#{formBeanPIS08.seriesPhoto}"></p:graphicImage></TD>
Bean:
public void handleUploadSeriesPhoto(FileUploadEvent event) {
try {
InputStream inputStream = event.getFile().getInputstream();
seriesPhoto = new DefaultStreamedContent(inputStream, "image/png");
} catch (Exception e) {
log.error(e.getMessage());
e.printStackTrace();
}
}
After upload photo, the following error occur:
Root cause of ServletException.
java.lang.NullPointerException
at com.sun.faces.mgbean.BeanManager$ScopeManager$ViewScopeHandler.getFromScope(BeanManager.java:559)
at com.sun.faces.mgbean.BeanManager$ScopeManager.getFromScope(BeanManager.java:473)
at com.sun.faces.mgbean.BeanManager.getBeanFromScope(BeanManager.java:236)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:189)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:73)
Truncated. see log file for complete stacktrace
>
StreamedContent Cannot display photo
I try to change the
seriesPhoto = new DefaultStreamedContent(inputStream, "image/png");
to
seriesPhoto = null;
And then there is no error after upload the photo. It seems the steamedContent cannot show in the p:graphicImage. Any one have been tried this error. Thanks.
seriesPhoto = new DefaultStreamedContent(inputStream, "image/png");
to
seriesPhoto = null;
And then there is no error after upload the photo. It seems the steamedContent cannot show in the p:graphicImage. Any one have been tried this error. Thanks.
- snooperman
- Posts: 155
- Joined: 06 Nov 2012, 18:43
With a little (5 seconds) google search, I found this.
var details = {
. . PF.version: "5.0.x",
. . JSF.version: "2.x",
. . Tomcat.version: "8.x"
}
. . PF.version: "5.0.x",
. . JSF.version: "2.x",
. . Tomcat.version: "8.x"
}
-
- Information
-
Who is online
Users browsing this forum: No registered users and 29 guests