好吧,这个小问题让我抓狂,我得到了渲染条件,在数据表中显示图像而不是文本,我有一种从文件中获取流内容的方法。
由于某些原因我不知道,该方法是bean调用两次,我将一个变量imageName传递给第一次获取流内容的方法,因为输入if,但是第二次变量去“”,我没有得到图像。我知道这是因为第二次进入else语句并显示missing.png图像......
我正在使用运行mojarra 2.1.9和primefaces 3.5
的GlassFish 3.1.2XHTML:
<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方法
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);
}
}
我在Stackoverflow中已经阅读了一些类似的问题,但它们并不清楚,它们看起来不像我的问题所以请帮助我已经这几个小时... ...