Jsf 如何将Primefaces对话框(对话框框架)显示为CustomExceptionHandler的一部分
我有一个CustomExceptionHandler,我想从中显示一个模式对话框,使用Primefaces对话框框架从用户那里获取一些信息 当我故意导致空指针异常时,CustomExceptionHandlerhandle方法按预期被调用。如果我在xhtml页面上直接从p:commandButton的actionListener调用对话框的.xhtml页面,我可以显示对话框的.xhtml页面并与之交互,无论是启用ajax还是禁用ajax 当我在禁用ajax的情况下调用p:commandButton以消除可能的ajax错误,从而使导致NPE的页面上的场景复杂化时,从CustomExceptionHandlerhandle生成前后日志消息,但不会显示对话框页面。不过,窗口会闪烁,好像正在刷新一样 从CustomExceptoinHandler.java:Jsf 如何将Primefaces对话框(对话框框架)显示为CustomExceptionHandler的一部分,jsf,primefaces,dialog,custom-exceptions,Jsf,Primefaces,Dialog,Custom Exceptions,我有一个CustomExceptionHandler,我想从中显示一个模式对话框,使用Primefaces对话框框架从用户那里获取一些信息 当我故意导致空指针异常时,CustomExceptionHandlerhandle方法按预期被调用。如果我在xhtml页面上直接从p:commandButton的actionListener调用对话框的.xhtml页面,我可以显示对话框的.xhtml页面并与之交互,无论是启用ajax还是禁用ajax 当我在禁用ajax的情况下调用p:commandButto
public class CustomExceptionHandler
extends ExceptionHandlerWrapper
{
private ExceptionHandler wrapped;
public CustomExceptionHandler(ExceptionHandler wrapped)
{
this.wrapped = wrapped;
}
@Override
public ExceptionHandler getWrapped()
{
return wrapped;
}
@Override
public void handle()
throws FacesException
{
Iterator<ExceptionQueuedEvent> iterator = getUnhandledExceptionQueuedEvents().iterator();
while (iterator.hasNext()) {
boolean removeError = false;
Throwable t = iterator.next().getContext().getException();
while (t.getCause() != null)
t = t.getCause();
if (t instanceof NullPointerException) {
Logging.devLogger.warn("NPE exception handler before dialog");
Map<String, Object> options = new HashMap<>();
options.put("modal", true);
String page = "/home/dialogs/exceptionDialog.xhtml";
RequestContext.getCurrentInstance().openDialog(page, options, null);
Logging.devLogger.warn("NPE exception handler after dialog");
removeError = true;
} // TBD: other cases and refactoring ....
if (removeError) iterator.remove();
}
getWrapped().handle();
}
}
处理异常和通过commandButton直接打开对话框时,RequestContext….openDialog调用是相同的。我已经确定,当在异常情况之外打开对话框时,会构造作用域为exception dialog视图的支持bean,但在处理未调用的exception@PostConstruct方法时,在打开对话框时不会构造
如何更改异常的处理方式以使对话框按预期运行?我使用的是Mojarra 2.2.5、Primefaces 4.0、Glassfish 4.0。我使用的是Primefaces 5.2,我用其他方式解决了这个问题 为了显示对话框,我在名为errorDialog的模板中创建了error对话框,并通过我使用的CustomExceptionHandler显示它,这个命令
RequestContext.getCurrentInstance().execute("PF('errorDialog').show();");
不能使用下面的命令,因为已经存在异常,因此可以渲染对话框
关于@PostConstruct方法的异常处理,我使用了:
@PostConstruct
private void init() {
try {
initController();
} catch (Exception ex) {
logger.error(ex, null);
//Show the error dialog
MyUtil.openErrorDialog();
}
}
注意:我仍然有一个问题,当发生异常错误500并由应用服务器而不是我的CustomHandlerClass处理时,我无法显示该对话框,因为应用服务器已经重定向了
@PostConstruct
private void init() {
try {
initController();
} catch (Exception ex) {
logger.error(ex, null);
//Show the error dialog
MyUtil.openErrorDialog();
}
}