Why can't I update a p:graphicImage twice after upload a file with p:uploadFile

江枫思渺然 提交于 2020-01-02 08:20:28

问题


I have been trying to upload an image with a p:uploadFile and it work fine at first time, but after the first uploaded file it not update the p:graphicImage, but if I reload the page the value of the graphicImage is fine and the image is showed. So, I think that is a problem with the primefaces uploadFile component, but I not sure.

My xhtml is this:

<h:form id="formNuevo" size="150%"  enctype="multipart/form-data">

    <h:outputLabel value="Diseño Neumatico: *" />
<p:fileUpload fileUploadListener="#{serviciosVentanaDiseno.manejarUploadedFile}" mode="advanced" auto="true" sizeLimit="9000000000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" update="mensajes graficImage"/>                          

<p:graphicImage id="graficImage" styleClass="disenoNeumatico" value="#{serviciosVentanaDiseno.streamedContentImagen}" ajax="true"/>



 </h:form>

and my bean is a @SessionScoped bean, it's here:

public void manejarUploadedFile(FileUploadEvent event) {
    UploadedFile uploadedFile = (UploadedFile)event.getFile();
    try {                    
        diseno.setImagen(uploadedFile.getContents());
        streamedContentImagen = new DefaultStreamedContent(new    ByteArrayInputStream(diseno.getImagen()));
    } catch (IOException e) {
        //log error
    }
}

public StreamedContent getStreamedContentImagen() {
    return streamedContentImagen;
}

public void setStreamedContentImagen(StreamedContent streamedContentImagen) {
    this.streamedContentImagen = streamedContentImagen;
}

回答1:


Try setting the cache attribute of the graphicImage component to false: <p:graphicImage cache="false"




回答2:


change scope @SessionScoped then <p:graphicImage cache="false">



来源:https://stackoverflow.com/questions/20082354/why-cant-i-update-a-pgraphicimage-twice-after-upload-a-file-with-puploadfile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!