Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
JSF Exception Handling with Spring AOP
<beans ...>
<!-- We can use annotations instead of xml <3 -->
<bean id="exceptionHandler"
<aop:aspect id="exceptionHandlerAspect" ref="exceptionHandler">
<aop:pointcut id="managedBeanMethods"
expression="execution(**.*(..)) and bean(*Bean)"/>
<aop:around pointcut-ref="managedBeanMethods" method="handle" />
import org.apache.commons.lang.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
public class ExceptionHandler {
* Default error message
public static final String internalErrorMessage = "And internal server error has happened, please contact our support for more details.";
* Handles any exceptions thrown from the managed beans
public Object handle(ProceedingJoinPoint pjp) {
try {
return pjp.proceed();
} catch (Throwable e) {
String message = StringUtils.defaultString(e.getMessage());
if (!message.isEmpty())
message = " [" + message + "]";
FacesUtils.addErrorMessage(internalErrorMessage + message); // Use DI if you can (an example:
return null; // keeps in the same page

This comment has been minimized.

Copy link
Owner Author

rponte commented Sep 20, 2012

configuring exception handling with jsf2.0,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.