<p:graphicImage> 在#{bean.foo().bar()} 上抛出 javax.el.PropertyNotFoundException,但#{bean.fooAndBar()} 有效

<p:graphicImage> throws javax.el.PropertyNotFoundException on #{bean.foo().bar()}, but #{bean.fooAndBar()} works

这是辅助 bean,它向模型中的对象发送消息以获取值。

@Model
public class ManageUsersBean {

    public ImageField getProfilePicField() { 
        return getSelectedMaskedEntity().getProfilePicField(); 
    }

    public StreamedContent paintProfilePic() { 
        return getProfilePicField().paint(); 
    }
}

public class ImageField
{
    public StreamedContent paint() {
        return paintPicture(getValue(), getPropertyName(), imageMimeTypeSupplier.get());
    }
}

为什么下面的EL可以正常工作:

<p:graphicImage value="#{manageUsersBean.paintProfilePic()}"/>

但以下不起作用:

<p:graphicImage value="#{manageUsersBean.getProfilePicField().paint()}"/>

结果是 PropertyNotFoundException: Target Unreachable, 'null' returned null.

完整堆栈跟踪:

[javax.enterprise.resource.webcontainer.jsf.context] (default task-50) Exception when handling error trying to reset the response.: java.io.IOException: javax.el.PropertyNotFoundException: Target Unreachable, 'null' returned null
    at org.primefaces.component.graphicimage.GraphicImageRenderer.encodeEnd(GraphicImageRenderer.java:43) [primefaces-5.2.jar:5.2]
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:88) [primefaces-5.2.jar:5.2]
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:71) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:206) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:123) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:58) [primefaces-5.2.jar:5.2]
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:88) [primefaces-5.2.jar:5.2]
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:71) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeRow(PanelGridRenderer.java:196) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeStaticBody(PanelGridRenderer.java:151) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeTableBody(PanelGridRenderer.java:104) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeTableLayout(PanelGridRenderer.java:65) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:37) [primefaces-5.2.jar:5.2]
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:88) [primefaces-5.2.jar:5.2]
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:71) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.fieldset.FieldsetRenderer.encodeContent(FieldsetRenderer.java:94) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.fieldset.FieldsetRenderer.encodeMarkup(FieldsetRenderer.java:76) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.fieldset.FieldsetRenderer.encodeEnd(FieldsetRenderer.java:47) [primefaces-5.2.jar:5.2]
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:88) [primefaces-5.2.jar:5.2]
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:71) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeRow(PanelGridRenderer.java:196) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeStaticBody(PanelGridRenderer.java:151) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeTableBody(PanelGridRenderer.java:104) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeTableLayout(PanelGridRenderer.java:65) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:37) [primefaces-5.2.jar:5.2]
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:176) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:84) [primefaces-5.2.jar:5.2]
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:71) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeRow(PanelGridRenderer.java:196) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeStaticBody(PanelGridRenderer.java:151) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeTableBody(PanelGridRenderer.java:104) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeTableLayout(PanelGridRenderer.java:65) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:37) [primefaces-5.2.jar:5.2]
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:88) [primefaces-5.2.jar:5.2]
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:71) [primefaces-5.2.jar:5.2]
    at org.primefaces.extensions.component.layout.LayoutPaneRenderer.encodeBegin(LayoutPaneRenderer.java:152) [primefaces-extensions-3.2.0.jar:3.2.0]
    at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:81) [primefaces-5.2.jar:5.2]
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:71) [primefaces-5.2.jar:5.2]
    at org.primefaces.extensions.component.layout.LayoutPaneRenderer.encodeBegin(LayoutPaneRenderer.java:152) [primefaces-extensions-3.2.0.jar:3.2.0]
    at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1855) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:461) [jsf-impl-2.2.6-jbossorg-4.jar:]
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133) [jsf-impl-2.2.6-jbossorg-4.jar:]
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) [jsf-impl-2.2.6-jbossorg-4.jar:]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.2.6-jbossorg-4.jar:]
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) [jsf-impl-2.2.6-jbossorg-4.jar:]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:78) [primefaces-5.2.jar:5.2]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:123) [undertow-websockets-jsr-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at com.foo.presentation.filter.NoCacheFilter.doFilter(NoCacheFilter.java:43) [classes:]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.access[=17=]0(ServletInitialHandler.java:73) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at io.undertow.server.HttpServerExchange.run(HttpServerExchange.java:727) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_05]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_05]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_05]
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, 'null' returned null
    at com.sun.el.parser.AstValue.getTarget(AstValue.java:192) [javax.el-3.0.0.jar:]
    at com.sun.el.parser.AstValue.getType(AstValue.java:86) [javax.el-3.0.0.jar:]
    at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201) [javax.el-3.0.0.jar:]
    at org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
    at org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
    at org.primefaces.el.ValueExpressionAnalyzer.intercept(ValueExpressionAnalyzer.java:69) [primefaces-5.2.jar:5.2]
    at org.primefaces.el.ValueExpressionAnalyzer.getExpression(ValueExpressionAnalyzer.java:44) [primefaces-5.2.jar:5.2]
    at org.primefaces.util.DynamicResourceBuilder.build(DynamicResourceBuilder.java:52) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.graphicimage.GraphicImageRenderer.getImageSrc(GraphicImageRenderer.java:75) [primefaces-5.2.jar:5.2]
    at org.primefaces.component.graphicimage.GraphicImageRenderer.encodeEnd(GraphicImageRenderer.java:41) [primefaces-5.2.jar:5.2]
    ... 100 more

更新:

issue (#476) 已修复,应该可以在 PrimeFaces v. 5.3 中使用,但我还没有机会对其进行测试。

org.primefaces.el.ValueExpressionAnalyzer没想到这里有嵌套的方法调用。只需将其设为嵌套 属性 调用即可。

<p:graphicImage value="#{manageUsersBean.profilePicField.paint()}"/>