上传后无法显示图像。我尝试过Display uploaded image in JSF,ManagedBean return null to graphicImage in Primefaces,Display database blob images in <p:graphicImage> inside <ui:repeat>。但是找不到问题
这是我的XHTML代码
<p:fileUpload fileUploadListener="#{watermarkController.handleFileUpload}"
update="img" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>
<p:graphicImage id="img" value="#{watermarkController.resultFile}"/>
我的豆子
@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();
}
}