Pages

Wednesday, April 10, 2013

JSF 2.x Tip of the Day: Post Exception Back Button

Introduction

This is hopefully one simple example of how to make a "back" button when an exception occurs, and sends you to an exception page. The question becomes "How do I get back to the page where the exception occurred?" The navigation back to the offending page is possible, but you want to make sure that you handle the exception, or you may get into a cycle.

A solution was suggested to me by my friend Markus Eisele using an ExceptionHandler in JSF. I had used exception handlers in the past, and thought that it was a simple and elegant idea. The code I am providing below DOES NOT handle the exception. This is specific to your implementation. This is just a handler that sits on top of your exception hierarchy, and provides a convenient mechanism to navigate back.

Code

The example code for the NetBeans Maven project can be downloaded from BitBucket here: exception-handler-navigation-button

You will need to register the factory below in the faces-config.xml file.

GeneralExceptionHandlerFactory.java


GeneralExceptionHandler.java


Usage

Here is an example of how to use it from an exception page.

0 comments :