我在门户网站上使用Mojarra 2.1.13和Spring。我在复合组件中有一个命令按钮,其操作在客户端中定义。当action方法发生异常时,会完全吞下此异常并抛出异常,这使得调试变得困难。
我创建了一个SSCCE。这是复合词simpleBtn.xhtml
:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
<composite:attribute name="action" targets="button" required="true" />
<composite:attribute name="label" />
<composite:attribute name="update" />
<composite:attribute name="execute" targets="button" />
</composite:interface>
<composite:implementation>
<h:commandButton id="button" value="#{cc.attrs.value}">
<f:ajax render="#{cc.attrs.update}" execute="#{cc.attrs.execute}" />
</h:commandButton>
</composite:implementation>
</html>
这是Spring托管bean com.example.Bean
:
@Component
@Scope("view")
public class Bean {
public void execute() {
Object o = new Integer(2);
System.out.println((String) o); // Class cast exception thrown here
}
}
这是视图,page.xhtml
:
<h:body>
<h:form>
<button:simpleBtn label="button" action="#{bean.execute}" />
</h:form>
</h:body>
按下按钮时,您希望在日志中看到ClassCastException
。但是,这种情况并没有发生。而是实际记录以下内容:
...
Caused by: javax.portlet.faces.BridgeException: javax.faces.FacesException: can't parse argument number: bean.execute
...
Caused by: javax.faces.FacesException: can't parse argument number: bean.execute
...
Caused by: java.lang.IllegalArgumentException: can't parse argument number: bean.execute
...
Caused by: java.lang.NumberFormatException: For input string: "bean.execute"
...
我进行了调试,我注意到ClassCastException
方法catch (ELException ele) {...}
阻止了ContextualCompositeMethodExpression#invoke(ELContext, Object[])
,但ele
因为新引发的异常而永远不会被抛出几行以后catch (Exception ex)
抛出。
这是如何引起的?如何让ClassCastException
显示在日志中呢?