我无法在 primefaces 图形图像组件上显示数据库中的图像。我正在使用 primefaces 3.4.2、jsf 2.2、glassfish 3.1.2.2。以下是我正在尝试的简单代码。我浏览了与 p:graphicimage 相关的其他帖子并采纳了这些建议,但我仍然无法完成这项工作。这里有什么问题?
索引.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form id="f1">
<p:panel style="height: 500px ; width: 800px" visible="true">
<p:graphicImage value="#{treeBean.image}" />
</p:panel>
</h:form>
</h:body>
</html>
树豆.java
@Named
@ApplicationScoped
public class TreeBean implements Serializable{
@EJB
private ImageEJB imageEjb;
public StreamedContent getImage() throws IOException{
FacesContext context = FacesContext.getCurrentInstance();
if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
return new DefaultStreamedContent();
}
else {
Decisiontree dr = imageEjb.getTree();
return new DefaultStreamedContent(new ByteArrayInputStream(dr.getImage()));
}
}
}
这是我在浏览器控制台中看到的。