3

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;
}
leoJerez
  • 55
  • 1
  • 9

2 Answers2

5

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

Emil Kaminski
  • 1,886
  • 2
  • 16
  • 26
0

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

I don't know
  • 701
  • 2
  • 8
  • 15
  • 1
    Could you please elaborate more your answer adding a little more description about the solution you provide? – abarisone Jun 08 '16 at 06:53