JSF: Cannot catch ViewExpiredException

可紊 提交于 2019-11-28 19:53:55

This test case is bogus. The ViewExpiredException is usually only thrown during restoring the view (because it's missing in the session), not during rendering the response nor instantiating the bean. In your case this exception is thrown during instantiating the bean and this exception is been wrapped in a ServletException.

The real ViewExpiredException is usually only thrown when you send a HTTP POST request to the server while the HTTP session is expired. So there are basically two ways to reproduce this reliably:

  1. Open a JSF page with a POST form (h:form is by default already POST) in a webbrowser, shutdown the server and clean its work directory (important, because most servers will serialize open sessions to disk on shutdown and unserialize them on startup), restart the server and submit the already opened form. A ViewExpiredException will be thrown.

  2. Set the <session-timeout> in web.xml to 1 minute and submit the form over 1 minute after opening the JSF page with the POST form. This will throw the ViewExpiredException as well.

I am not an expert. These are just wild guesses or suggestions.

1) Try redirecting to a standard HTML page to see if that works 2) Based on this , it should work with the first approach itself, try writing a JSF PhaseListener and throw the same exception in the RESTORE VIEW Phase.Right now, you are throwing either in the INVOKE APPLICATION or UPDATE MODEL Phase. 3) By a sysout , make sure that the error page is configured - using Servlet Context (I have not tried this but It should be possible)

Even I am curious what could be the problem is!!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!