JSFでStrutsのglobal exceptionライクな実装
Struts脳からJSF脳になかなか切り替わらずちょくちょく困ったりしています。
例外処理についてJSFでStrutsのglobal exceptionライクな実装をしようと思い少し調べてみました。
類似の設定であるweb.xmlのerror-pageでもいいんですが、なぜJSFの中でハンドルすべきかは以下の通り考察されています。*1
However one thing what a customExceptionHandler is really useful for is that it allows you to deal with exceptions during ajax requests.
具体的な実装はfaces-config.xmlへの設定とハンドラの実装になります。
faces-config.xmlの実装は以下の通り。
com.common.exceptions.CustomExceptionHandlerFactory
ハンドラの実装は以下の通り。
String errorPageLocation = "/WEB-INF/errorpages/500.xhtml"; context.setViewRoot(context.getApplication().getViewHandler().createView(context, errorPageLocation)); context.getPartialViewContext().setRenderAll(true); context.renderResponse();