上传图像后显示图像

时间:2015-05-11 11:17:10

标签: jsf jsf-2 primefaces

上传后无法显示图像。我尝试过Display uploaded image in JSFManagedBean return null to graphicImage in PrimefacesDisplay 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();
    }

}

0 个答案:

没有答案