[英]primefaces graphicimage from database not loading
我在Primefaces graphicimage組件上無法顯示數據庫中的圖像。 我正在使用primefaces 3.4.2,jsf 2.2,glassfish 3.1.2.2。 以下是我正在嘗試的簡單代碼。 我瀏覽了其他與p:graphicimage有關的帖子,並納入了建議,但我仍然不願做這項工作。 怎么了
的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
@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()));
}
}
}
這是我在瀏覽器控制台中看到的。
在web.xml中添加MIME類型,如下所示:-
<mime-mapping> <extension>xhtml</extension> <mime-type>image/svg+xml</mime-type> </mime-mapping>
如下更改您的bean中的return語句:
return new DefaultStreamedContent(new ByteArrayInputStream(dr.getImage()),"image/svg+xml");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.