假设一个 facelets 有 10 个输出文本,这些输出文本与值表达式绑定到 bean 中的 10 个不同字段。如果调用第一个getter时出现异常,是否还应该调用后面的9?
因为这是我在测试时看到的行为。它会导致已升级为使用 JSF 2 的遗留模块出现严重问题。
我正在使用 Mojarra 2.1.16 并尝试使用 Mojarra 2.1.6。尝试使用焊接和 JSF2 bean。容器是Tomcat 7。
这种行为可以以某种方式改变吗?我无法想象这是理想的行为。
我用来在下面重现它的代码:
编辑:这不是生产代码,这只是显示了意外的行为。
相关的facelet代码:
<h:inputText value="#{testController.a}"></h:inputText>
<h:inputText value="#{testController.b}"></h:inputText>
<h:inputText value="#{testController.c}"></h:inputText>
<h:inputText value="#{testController.d}"></h:inputText>
<h:inputText value="#{testController.e}"></h:inputText>
<h:inputText value="#{testController.f}"></h:inputText>
<h:inputText value="#{testController.g}"></h:inputText>
<h:inputText value="#{testController.h}"></h:inputText>
相关bean代码
private String a, b, c ,d, e, f, g, h;
public String getA() throws Exception {
throw new Exception();
}
public void setA(String a) {
this.a = a;
}
public String getB() {
System.out.println("b was called");
return b;
}
public void setB(String b) {
this.b = b;
}
public String getC() {
System.out.println("c was called");
return c;
}
public void setC(String c) {
this.c = c;
}
public String getD() {
System.out.println("d was called");
return d;
}
public void setD(String d) {
this.d = d;
}
public String getE() {
System.out.println("e was called");
return e;
}
public void setE(String e) {
this.e = e;
}
public String getF() {
System.out.println("f was called");
return f;
}
public void setF(String f) {
this.f = f;
}
public String getG() {
System.out.println("g was called");
return g;
}
public void setG(String g) {
this.g = g;
}
public String getH() {
System.out.println("h was called");
return h;
}
public void setH(String h) {
this.h = h;
}
带有托管 bean 的 JSF 2.1.6:
2013-jan-09 13:54:41 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jre6\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\CollabNet\Subversion Client;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\ThinkPad\Bluetooth Software\;C:\Program Files\ThinkPad\Bluetooth Software\syswow64;C:\Program Files (x86)\TortoiseSVN\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\cvsnt;C:\Program Files (x86)\cvsnt1;C:\Program Files\SlikSvn\bin\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Groovy\Groovy-1.8.6\bin;c:\projects\maven\bin;;.
2013-jan-09 13:54:41 org.apache.tomcat.util.digester.SetPropertiesRule begin
VARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:demo' did not find a matching property.
2013-jan-09 13:54:41 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8090"]
2013-jan-09 13:54:41 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8010"]
2013-jan-09 13:54:41 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 706 ms
2013-jan-09 13:54:41 org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
2013-jan-09 13:54:41 org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.29
2013-jan-09 13:54:47 com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.1.6 (SNAPSHOT 20111206) for context '/demo'
2013-jan-09 13:54:48 com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present. ManagedBeans methods marked with these annotations will have said annotations processed.
2013-jan-09 13:54:51 org.richfaces.javascript.ClientServiceConfigParser parse
VARNING: Found JavaScript function definition for class javax.validation.constraints.NotNull, but that class is not presented
2013-jan-09 13:54:51 org.richfaces.javascript.ClientServiceConfigParser parse
VARNING: Found JavaScript function definition for class org.hibernate.validator.constraints.NotEmpty, but that class is not presented
2013-jan-09 13:54:51 org.richfaces.javascript.ClientServiceConfigParser parse
VARNING: Found JavaScript function definition for class javax.validation.constraints.Size, but that class is not presented
2013-jan-09 13:54:51 org.richfaces.javascript.ClientServiceConfigParser parse
VARNING: Found JavaScript function definition for class javax.validation.constraints.Pattern, but that class is not presented
2013-jan-09 13:54:51 org.richfaces.javascript.ClientServiceConfigParser parse
VARNING: Found JavaScript function definition for class javax.validation.constraints.Min, but that class is not presented
2013-jan-09 13:54:51 org.richfaces.javascript.ClientServiceConfigParser parse
VARNING: Found JavaScript function definition for class javax.validation.constraints.Max, but that class is not presented
2013-jan-09 13:54:51 org.richfaces.javascript.ClientServiceConfigParser parse
VARNING: Found JavaScript function definition for class javax.validation.constraints.AssertTrue, but that class is not presented
2013-jan-09 13:54:51 org.richfaces.javascript.ClientServiceConfigParser parse
VARNING: Found JavaScript function definition for class javax.validation.constraints.AssertFalse, but that class is not presented
2013-jan-09 13:54:51 org.richfaces.cache.CacheManager getCacheFactory
INFO: Selected fallback cache factory
2013-jan-09 13:54:51 org.richfaces.cache.lru.LRUMapCacheFactory createCache
INFO: Creating LRUMap cache instance using parameters: {facelets.DEVELOPMENT=true, javax.faces.PROJECT_STAGE=Development, org.richfaces.enableControlSkinning=true, javax.faces.DEFAULT_SUFFIX=.xhtml}
2013-jan-09 13:54:51 org.richfaces.cache.lru.LRUMapCacheFactory createCache
INFO: Creating LRUMap cache instance of 512 items capacity
2013-jan-09 13:54:51 org.richfaces.application.InitializationListener onStart
INFO: RichFaces Core Implementation by JBoss by Red Hat, version v.4.2.0.Final
2013-jan-09 13:54:51 com.sun.faces.config.ConfigureListener$WebConfigResourceMonitor$Monitor <init>
INFO: Monitoring jndi:/localhost/demo/WEB-INF/faces-config.xml for modifications
2013-jan-09 13:54:52 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8090"]
2013-jan-09 13:54:52 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8010"]
2013-jan-09 13:54:52 org.apache.catalina.startup.Catalina start
INFO: Server startup in 10510 ms
2013-jan-09 13:55:30 com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
ALLVARLIG: Error Rendering View[/rdfieldset/rdfieldset.xhtml]
javax.el.ELException: /rdfieldset/rdfieldset.xhtml @13,42 value="#{testController.a}": Error reading 'a' on type com.wmdata.raindance.webcomp.links.demo.TestController
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIOutput.getValue(UIOutput.java:169)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.wmdata.raindance.webcomp.fileUpload.FileUploadFilter.doFilter(FileUploadFilter.java:67)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.Exception
at com.wmdata.raindance.webcomp.links.demo.TestController.getA(TestController.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:87)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 39 more
b was called
c was called
d was called
e was called
f was called
g was called
h was called
带有 CDI bean 的 JSF 2.1.16
jan 09, 2013 1:59:52 EM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
SEVERE: Error Rendering View[/start.xhtml]
javax.el.ELException: /start.xhtml @26,49 value="#{testController.a}": Error reading 'a' on type test.testController$Proxy$_$$_WeldClientProxy
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIOutput.getValue(UIOutput.java:169)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:424)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at org.apache.myfaces.extensions.cdi.jsf2.impl.listener.phase.CodiLifecycleWrapper.render(CodiLifecycleWrapper.java:126)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.Exception
at test.testController.getA(testController.java:44)
at test.testController$Proxy$_$$_WeldClientProxy.getA(testController$Proxy$_$$_WeldClientProxy.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:87)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 39 more
b was called
c was called
d was called
e was called
f was called
g was called
h was called