Question

I would like to dynamically set an error page in JSF. Specifically what I would like to do is whenever I get a ViewExpiredException to refresh the page. I am currently using omnifaces FullAjaxExceptionHandler to manage my exception but it reads the error pages from web.xml.

Is there an easy way to do this? Should I consider client side navigation by using onError event or just overwrite FullAjaxExceptionHandler.findErrorPageLocation ?

Was it helpful?

Solution

It reads error pages from web.xml because that's the standard way how they are used if you didn't use JSF ajax in first place. In other words, the FullAjaxExceptionHandler ensures that the exception handling and error page presentation behaves exactly the same as if when you wouldn't be using ajax by e.g. <h:commandButton> without <f:ajax>, or <p:commandButton ajax="false">, or because enduser has JS disabled.

You can indeed control it by extending the exception handler and overriding findErrorPageLocation method, but then it won't behave anymore the same way as the standard way.

Alternatively, and likely a better way in your specific case, is to just specify a specific error page for ViewExpiredException and grab the initial page by the usual request attribute and let JavaScript redirect to it on page load.

<h:outputScript>
    window.location = "#{requestScope['javax.servlet.error.request_uri']}";
</h:outputScript>

As a bonus, it will work exactly the same way as when you wouldn't be using JSF ajax.


I only wonder how this all would improve the user experience. This is likely only more confusing to the enduser; a page which reloads itself without any additional feedback when the session has expired during a postback.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top