我尝试应用 a4j:mediaOutput 来打印以前保存的 jpeg 文件。它因 bean-scope-error 而失败。我在流程周期中做了一些测试。
- 该文件存储在数据库中。
- 我可以从数据库中读取并使用
FileOutputStream
. JPEG看起来不错。 - 但是,paint 方法永远不会被触发。System.out 处的断点永远不会到达。这很奇怪,因为支持 bean 调用了一个 getter 方法,我用它来设置 a4j:mediaOutput 的 value 属性。
value
因此,在和createContent
属性处理之间的顺序是错误。
这是我的@ViewScoped
backing bean的方法。
public void paintHeaderImage(OutputStream stream, Object object)
throws IOException {
UploadedImage ui = pub.getUploadedImages().iterator().next();
stream.write(ui.getData());
stream.close();
}
JSF/Richfaces 片段。
<a4j:mediaOutput fileName="header.jpg" element="img" createContent="#{pubController.paintHeaderImage}" value="#{pubController.headerImage.pid}" mimeType="image/jpeg" style="width:100px; height:100px;" />
下面是错误。显然它发生在 RENDER_RESPONSE 之后(参见日志的第一行)
18:12:22,477 INFO [org.exadel.helper] (http--0.0.0.0-8080-1) AFTER RENDER_RESPONSE 6
18:12:22,636 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ccms].[Faces Servlet]] (http--0.0.0.0-8080-1) Servlet.service() for servlet Faces Servlet threw exception: java.lang.NullPointerException
at com.sun.faces.mgbean.BeanManager$ScopeManager$ViewScopeHandler.getFromScope(BeanManager.java:563) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.mgbean.BeanManager$ScopeManager.getFromScope(BeanManager.java:477) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.mgbean.BeanManager.getBeanFromScope(BeanManager.java:240) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:242) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) [jsf-impl-2.1.7-jbossorg-2.jar:]
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72) [jbossweb-7.0.13.Final.jar:]
at org.apache.el.parser.AstValue.getTarget(AstValue.java:94) [jbossweb-7.0.13.Final.jar:]
at org.apache.el.parser.AstValue.invoke(AstValue.java:244) [jbossweb-7.0.13.Final.jar:]
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) [jbossweb-7.0.13.Final.jar:]
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) [jsf-impl-2.1.7-jbossorg-2.jar:]
at org.richfaces.resource.MediaOutputResource.encode(MediaOutputResource.java:62) [richfaces-components-ui-4.3.3.Final.jar:4.3.3.Final]
at org.richfaces.resource.UserResourceWrapperImpl.encode(UserResourceWrapperImpl.java:188) [richfaces-core-impl-4.3.3.Final.jar:4.3.3.Final]
at org.richfaces.resource.ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:229) [richfaces-core-impl-4.3.3.Final.jar:4.3.3.Final]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:591) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_17]
img 标签已创建,但非常长。浏览器无法检索它,就好像资源不可用一样。
<img style="width:100px; height:100px;" src="/ccms/rfRes/org.richfaces.resource.MediaOutputResource.jsf?do=eAGFUj1oFEEY!XJwoCFFjD8gEricGhB0lmuS4gxIxJiDiylO!EmwmNv93NtldmcyM3u3GBUbG7EQbAMWtlpZCWlshbMIWqW0EAstxMbY-M0mGtkm2wws773vfe97r75BNdNwdLUd8z5ngqchW-7G6Nvmsw-3Xoybc6ICkCsAqBoNR!ZR81IK5Omwph992tj5XoGRFaj2uciQ0BZGo4SH6MUKQ0XEaUfM2V3uo2G-TJRMMbWsY7nFRSkC1B3eR337!Zu55xvDpQpU2nDYF9yYazxBCxOFP8!58zpWR2nYbMOoIU5QaFg4sYuIpNdBHXER3eNdgc1cufEXaCQzWbpnwNkQaA1Dwa7zcAltTwZXcqXRmEimtKz7RsZocw0nd60TtIzjEz!PzH9esy4hyvAfbl!p5eMnnR8rWxeLDF0MUocs7kpj2ABF4ObfpLcs3J1893FneqxGobbhUEBeQ8rJwqlix9xD4ZUpTXLQKKlnNhJuxILUA64DCq3M2n57!Pfw6eam87cGDylRDXWnwhX3e-jIZUorUaL1i2-Lxv0pF1BBG5yFqdPrKutelqnVUgjUTPEotYvI6bYt14UHAOWm7V3y9daNL18n16!-bVrFwrGiaJFky5lVmSUg8sTCePH7v5YqlQ!uwKpHl5OZpnJ5gygI6bQe7Y4LmRAs79lE1C41ZmfOz8zWfBKy6GxS!-bqB5qu59TlXrEFi1X4B2oTIgI_" id="j_idt18:pubFormE:j_idt63">