我使用的是与primefaces的JSF,并希望显示来自java代码的图像。JSF/primefaces以代码形式显示图像 - 图像位置?
我已经看到了http://www.primefaces.org/showcase/ui/dynamicImage.jsf
的教程,但我不是我怎么能得到正确我的映像文件的路径清晰:
代码:
豆:
@ManagedBean
public class ABean {
private StreamedContent bStatus;
public ABean() {
try {
Boolean connected = false;
if (connected == true) {
bStatus = new DefaultStreamedContent(new FileInputStream(new File("/images/greendot.png")), "image/jpeg");
} else {
bStatus = new DefaultStreamedContent(new FileInputStream(new File("/images/reddot.png")), "image/jpeg");
}
} catch(Exception e) {
e.printStackTrace();
}
}
public StreamedContent getBStatus() {
return bStatus;
}
public void setBStatus(StreamedContent bStatus) {
this.bStatus = bStatus;
}
}
xhtml:
<p:graphicImage value="#{ABean.bStatus}" />
个
回报:
java.io.FileNotFoundException:\影像\ reddot.png
我希望在哪里显示,当它形成的代码,以及如何做到这一点储存我的形象的最佳实践。
实际上你的图像位于哪里? – partlov 2013-02-28 16:01:46
我的图像位于WebContent/images /中 - 但我也打开了一个新的结构来存储我的图像以用于java代码。 – ctekk 2013-02-28 16:03:08