PrimeFaces GraphicImage 不显示由支持 bean 提供的 JPEG 图像

发布于 2024-12-14 12:27:43 字数 1181 浏览 2 评论 0原文

我正在尝试使用 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 包含正确的数据,并且在每次调用时向 PrimeFaces 返回一个非空 StreamedContent 对象。我在 Glassfish 的 server.log 中没有收到任何错误。当我将其作为文件引用而不是从数据库中提取时,相同的图像可以很好地显示在页面上。我不知道出了什么问题,也不知道如何更深入地调试它。任何提示将不胜感激。

I am trying to display a simple JPEG image using PrimeFaces (2.2.1) graphicImage tag as the following .xhtml segment shows:

<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>

The image is retrieved from a BLOB column in a DB2 database in the preRenderView event and stored in a byte[] until such time as logosBean.getCompanyLogo(), which consists of the following code, is invoked:

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

However, all that gets displayed is the image's alternate text. The first odd thing that is happening is that getCompanyLogo() is invoked 4 times after the preRenderView event for one refresh of the page. In the debugger, though, companyLogo contains the correct data and is returning a non-null StreamedContent object to PrimeFaces on each invocation. I am getting no errors in Glassfish's server.log. The same image displays on the page fine when I reference it as a file rather than pull it from the database. I have no idea what is going wrong nor do I have any idea how to debug it deeper. Any hints would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

熟人话多 2024-12-21 12:27:43

我发现将支持 bean 从 ConversationScoped 更改为 SessionScoped 可以解决该问题,但正如以下分析所示,某些地方肯定存在问题。

我决定查看生成的页面,看看它是否可以提供任何线索,其中有 。我的图像的标签:

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

在 Firefox 的源显示窗口中,它为 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 的 GraphicImage 和 Glassfish 之间、PF 和 Conversation 范围之间或其他地方是否存在某种不兼容。我想向某人提交错误报告,但我什至不确定 org.jboss 类属于谁。我想我将从PrimeFaces 论坛中的评论开始。

I found that changing my backing bean from ConversationScoped to SessionScoped works around the problem, but there's definitely something wrong somewhere as the following analysis shows.

I decided to take a look at the generated page to see if it might provide any clues, and in there was the <img> tag for my image:

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

In Firefox's Source display window it created a link for the src attribute, so I clicked on it and got another page of source that included the following error:

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)

I get the same error whether or not I actually begin a conversation (e.g. in the preRenderView event). I don't know if there's some kind of incompatibility between PrimeFaces' graphicImage and Glassfish, between PF and Conversation scopes, or somewhere else. I'd like to submit an error report to someone, but I'm not even sure who the org.jboss classes belong to. I guess I will start with a comment in the PrimeFaces forum.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文