2

我在门户上使用 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日志显示在日志中?

4

0 回答 0