vin*_*rry 6 java seam exception-handling
我正在使用seam 2.2,primefaces作为视图表示层.我会写一些基础设施来捕获所有异常.例如,我按照一段代码放入了一个facelets:
<p:commandButton actionListener="#{mySeamController.aMethod()}"
Run Code Online (Sandbox Code Playgroud)
在MySeamController类中,上面的方法:
public void aMethod()
{
throw new NullPointerException();
}
Run Code Online (Sandbox Code Playgroud)
在控制器中我写了一个方法:
@Observer("myapp.exceptions.exception")
public void onSystemException(Exception e)
{
System.out.println("a exception was occurred");
}
Run Code Online (Sandbox Code Playgroud)
我写了一个类来捕获异常:
@Scope(ScopeType.APPLICATION)
@BypassInterceptors
@Install( precedence = Install.MOCK, classDependencies = "javax.faces.context.FacesContext")
@Name("org.jboss.seam.exception.exceptions")
public class ExceptionHandler extends org.jboss.seam.exception.Exceptions{
private static final long serialVersionUID = 1L;
@Logger
Log log;
public void handle(Exception e) throws Exception
{
Events.instance().raiseEvent("myapp.exceptions.exception", e);
super.handle(e);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我使用actionListener时,我注意到了
<p:commandButton actionListener="#{mySeamController.aMethod()}"
Run Code Online (Sandbox Code Playgroud)
而不是一个动作
<p:commandButton action="#{mySeamController.aMethod()}"
Run Code Online (Sandbox Code Playgroud)
ExceptionHandler类没有观察到异常.为什么?有人可以帮忙吗?最好的祝福