jsf ajax,JSF Ajax请求中的异常处理

OmniFaces FullAjaxExceptionHandler展示柜中充实了这个问题。

基本上,您需要创建一个定制,ExceptionHandler因为标准JSF不会提供一个定制的定制(至少不是明智的选择)。在其中,您将可以接触Exception引起所有麻烦的实例。

这是一个启动示例:

public class YourExceptionHandler extends ExceptionHandlerWrapper {

private ExceptionHandler wrapped;

public YourExceptionHandler(ExceptionHandler wrapped) {

this.wrapped = wrapped;

}

@Override

public void handle() throws FacesException {

FacesContext facesContext = FacesContext.getCurrentInstance();

for (Iterator iter = getUnhandledExceptionQueuedEvents().iterator(); iter.hasNext();) {

Throwable exception = iter.next().getContext().getException(); // There it is!

// Now do your thing with it. This example implementation merely prints the stack trace.

exception.printStackTrace();

// You could redirect to an error page (bad practice).

// Or you could render a full error page (as OmniFaces does).

// Or you could show a FATAL faces message.

// Or you could trigger an oncomplete script.

// etc..

}

getWrapped().handle();

}

@Override

public ExceptionHandler getWrapped() {

return wrapped;

}

}

为了使其运行,请ExceptionHandlerFactory如下创建一个自定义:

public class YourExceptionHandlerFactory extends ExceptionHandlerFactory {

private ExceptionHandlerFactory parent;

public YourExceptionHandlerFactory(ExceptionHandlerFactory parent) {

this.parent = parent;

}

@Override

public ExceptionHandler getExceptionHandler() {

return new YourExceptionHandler(parent.getExceptionHandler());

}

}

需要进行以下注册faces-config.xml:

com.example.YourExceptionHandlerFactory

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值