Handling view expired
I promised you that we would add some finesse to our digital application. If you've worked with JSF for a while, you probably have your fair share of stack traces with javax.faces.application.ViewExpiredException
as the root cause. This is one of the most notorious exceptions. You could increase the HTTP Session lifetime in order to compensate for an out-of-date request, but how long is break away from the computer for an average person? Meanwhile, the objects would persist in the memory. There is a better way and that is by using the Web XML deployment descriptor.
Inside the applications web.xml
file, we need to trigger a redirection to a more pleasant error page. The following is an extract of the XML file:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" ...> <!-- ... --> <error-page> <exception-type> javax.faces.application.ViewExpiredException </exception-type> <location...