【问题标题】:primefaces graphicimage from database not loading数据库中的primefaces图形图像未加载
【发布时间】:2014-03-17 00:23:49
【问题描述】:

我无法在 primefaces graphicsimage 组件上显示数据库中的图像。我正在使用 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()));
        }
    }
}

这是我在浏览器控制台中看到的。

【问题讨论】:

    标签: java jsf jsf-2 primefaces graphicimage


    【解决方案1】:
    1. 在 web.xml 中添加 MIME 类型,如下所示:-

      <mime-mapping>
         <extension>xhtml</extension>
         <mime-type>image/svg+xml</mime-type>
      </mime-mapping>
      
    2. 如下更改 bean 中的 return 语句:-

      return new DefaultStreamedContent(new ByteArrayInputStream(dr.getImage()),"image/svg+xml");
      

    【讨论】:

      猜你喜欢
      • 2014-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多