[英]primefaces graphicimage from database not loading
I am having trouble displaying image from database on a primefaces graphicimage component. 我在Primefaces graphicimage组件上无法显示数据库中的图像。 I am using primefaces 3.4.2, jsf 2.2, glassfish 3.1.2.2.
我正在使用primefaces 3.4.2,jsf 2.2,glassfish 3.1.2.2。 Following is the simple code I am trying.
以下是我正在尝试的简单代码。 I went through other posts related to p:graphicimage and incorporated the recommendations, still I gouldnt make this work.
我浏览了其他与p:graphicimage有关的帖子,并纳入了建议,但我仍然不愿做这项工作。 What is wrong here?
怎么了
index.xhtml 的index.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>
TreeBean.java TreeBean.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()));
}
}
}
This is what I see in the browser console. 这是我在浏览器控制台中看到的。
Add a MIME type in web.xml like below:- 在web.xml中添加MIME类型,如下所示:-
<mime-mapping> <extension>xhtml</extension> <mime-type>image/svg+xml</mime-type> </mime-mapping>
Change your return statement in your bean as below:- 如下更改您的bean中的return语句:
return new DefaultStreamedContent(new ByteArrayInputStream(dr.getImage()),"image/svg+xml");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.