Skip to content

Instantly share code, notes, and snippets.

Last active September 23, 2015 18:08
Show Gist options
  • Save rponte/595436 to your computer and use it in GitHub Desktop.
Save rponte/595436 to your computer and use it in GitHub Desktop.
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
Copy link

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