PrimeFaces graphicImage不显示由辅助bean提供的JPEG图像

时间:2011-11-09 15:40:55

标签: jsf glassfish primefaces blob glassfish-3

我正在尝试使用PrimeFaces(2.2.1)graphicImage标记显示一个简单的JPEG图像,如下所示.xhtml段显示:

<f:metadata>
    <f:viewParam name="contractorid" value="#{logosBean.contractorID}" />
</f:metadata>
<body>
    <ui:composition template="./templates/userLayout.xhtml">
        <ui:define name="userContent">
            <f:event type="preRenderView" listener="#{logosBean.initialize}" />
            <h:form>
                <p:graphicImage value="#{logosBean.companyLogo}" alt="No Company Logo Set" />
            </h:form>
        </ui:define>
    </ui:composition>
</body>

在preRenderView事件中从DB2数据库中的BLOB列检索映像,并将其存储在byte []中,直到调用logosBean.getCompanyLogo()(包含以下代码)为止:

return( (companyLogo != null) ? new DefaultStreamedContent( new ByteArrayInputStream( companyLogo ) ) : null );

然而,所有显示的都是图像的替代文字。发生的第一件奇怪的事情是在preRenderView事件之后调用getCompanyLogo()4次以进行一次刷新页面。但是,在调试器中,companyLogo包含正确的数据,并在每次调用时将非空的StreamedContent对象返回给PrimeFaces。我在Glassfish的server.log中没有出错。当我将其作为文件引用而不是从数据库中提取时,页面上显示的图像相同。我不知道出了什么问题,也不知道如何更深入地调试它。任何提示都将不胜感激。

1 个答案:

答案 0 :(得分:1)

我发现将我的支持bean从ConversationScoped更改为SessionScoped解决了这个问题,但是下面的分析显示,某些地方肯定存在问题。

我决定查看生成的页面,看它是否可以提供任何线索,并且在那里有&lt; img&gt;标记为我的形象:

<img id="j_idt29:j_idt30"
src="/EnergySolutionsProfile/faces/MaintainLogos.xhtml?cid=1&amp;primefacesDynamicContent=logosBean.companyLogo"
alt="No Company Logo Set" />

在Firefox的Source显示窗口中,它为src属性创建了一个链接,所以我点击它并得到另一个包含以下错误的源页面:

org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.ConversationScoped
at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:664)
at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:77)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:87)
at com.MSCA.ESP.WebApp.org$jboss$weld$bean-web-ManagedBean-class_com$MSCA$ESP$WebApp$LogosBean_$$_WeldClientProxy.getCompanyLogo(org$jboss$weld$bean-web-ManagedBean-class_com$MSCA$ESP$WebApp$LogosBean_$$_WeldClientProxy.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(AstValue.java:116)
at com.sun.el.parser.AstValue.getValue(AstValue.java:163)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:55)
at org.primefaces.application.DynamicContentStreamer.streamDynamicContent(DynamicContentStreamer.java:66)
at org.primefaces.application.DynamicContentStreamer.beforePhase(DynamicContentStreamer.java:57)
at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)

无论我是否真正开始对话(例如在preRenderView事件中),我都会得到同样的错误。我不知道PrimeFaces和PrimeFaces之间是否存在某种不相容性。 graphicImage和Glassfish,PF和Conversation范围之间,或其他地方。我想向某人提交错误报告,但我甚至不确定org.jboss类属于谁。我想我会从comment in the PrimeFaces forum开始。