0

Ok, this little problem is driving me crazy, I got this rendered condition to show an image instead of text in a datatable, I have a method to get the streamed content from a file.

for some reason I don't know, the method is bean called twice, I'm passing a variable imageName to the method that get the streamed content the first time is ok because enters the if, but then the second time variable goes "" and I'm not getting the image. I know this because the second time enter in the else statement and the missing.png image is shown...

I'm using GlassFish 3.1.2 running mojarra 2.1.9 and primefaces 3.5

XHTML:

<p:column headerText="Respuesta">
                        <p:graphicImage width="200" height="200" value="#{viewFormResponseController.getImageFromPath(viewFormResponse.itemResponse)}" rendered="#{viewFormResponse.itemType == 'FIRMA'}"></p:graphicImage>
                        <h:outputText value="#{viewFormResponse.itemResponse}"></h:outputText>
                    </p:column>

Bean method

public StreamedContent getImageFromPath(String imageName) throws FileNotFoundException{
    System.out.println("image from path");
    String pathNoImage = "C:\\DataTraceServer\\missing.png";
        if(imageName != null && viewFormResponses != null && !imageName.equals("")){
    System.out.println(imageName);
    Device device;
    try {
        device = selectedFormResponse.getDevice();
        String path = "C:\\DataTraceServer\\"+selectedUser.getUsername()+"\\"+device.getImei()+"\\multimediaFile\\"+imageName;
        System.out.println(path);
        String contentType = FacesContext.getCurrentInstance().getExternalContext().getMimeType(path);
        return new DefaultStreamedContent(new FileInputStream(path), contentType);
        } catch (FileNotFoundException ex) {
            System.out.println("exception");
            Logger.getLogger(ViewFormResponseController.class.getName()).log(Level.SEVERE, null, ex);
            String contentType = FacesContext.getCurrentInstance().getExternalContext().getMimeType(pathNoImage);
            return new DefaultStreamedContent(new FileInputStream(pathNoImage), contentType);
        }
        } else {
            System.out.println("else");
            String contentType = FacesContext.getCurrentInstance().getExternalContext().getMimeType(pathNoImage);
            return new DefaultStreamedContent(new FileInputStream(pathNoImage), contentType);
        }

    }

I've read some similar questions here in Stackoverflow but they aren't clear and they don't look like my problem so please help I've been on this for hours...

  • Have you read this [excellent answer of BalusC in that thread](http://stackoverflow.com/a/2090062/913543) ? – LaurentG Jun 22 '13 at 05:31
  • yes, but I don't know how to apply it to my specific problem, can you give me some advice? thanks – John Gamarra González Jun 22 '13 at 05:43
  • possible duplicate of [How to use p:graphicImage with StreamedContent within p:dataTable?](http://stackoverflow.com/questions/8304967/how-to-use-pgraphicimage-with-streamedcontent-within-pdatatable) – skuntsel Jun 22 '13 at 09:34
  • possible duplicate of [Problems displaying database blob image in Primefaces graphicimage](http://stackoverflow.com/questions/10073905/problems-displaying-database-blob-image-in-primefaces-graphicimage) – BalusC Jun 22 '13 at 11:56
  • Here's another one, more detailed: http://stackoverflow.com/questions/8207325/display-image-from-database-with-pgraphicimage/12452144#12452144 – BalusC Jun 22 '13 at 11:59
  • Thanks, I'm sorry its a duplicate, same problem as the linked question by skuntsel – John Gamarra González Jun 25 '13 at 02:23

0 Answers0