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...