I'm not sure if the following is what the hints above meant, however it works, 
in case it can be useful to others. Thanks for the help.

-----------------------------
package myproject.tapestry.services;

import org.apache.tapestry5.plastic.MethodAdvice;

public interface ExceptionDisplayMethodAdvice extends MethodAdvice
{
       // No code in this subclass.
}

-----------------------------
package myproject.tapestry.services;

public class ExceptionDisplayMethodAdviceImpl implements 
ExceptionDisplayMethodAdvice
{
       @Inject
       private PageRenderLinkSource pageRenderLinkSource;

       @Inject
       private Response             response;

       /**
       * @see MethodAdvice#advise(MethodInvocation)
       */
       @Override
       public void advise(MethodInvocation invocation)
       {
              System.err.println(this.pageRenderLinkSource + ";" + 
this.response);

MethodInvocation result = invocation.proceed();

              if (result.didThrowCheckedException())
              {
                     Exception exception = 
result.getCheckedException(Exception.class);

                     Exception.printStackTrace();

                     // Redirect to the exception page :

                     result.setCheckedException(null);

                     Link exceptionDisplayPage = 
this.pageRenderLinkSource.createPageRenderLink(ExceptionDisplayPage.class);

                     try
                     {
                           this.response.sendRedirect(exceptionDisplayPage);
                     }
                     catch (IOException e)
                     {
                           e.printStackTrace();
                     }
              }
       }
}

-----------------------------
public class ExceptionDisplayWorker implements ComponentClassTransformWorker2
{
       @Inject
       private ExceptionDisplayMethodAdvice advice;

       @Override
       public void transform(PlasticClass plasticClass, TransformationSupport 
support, MutableComponentModel model)
       {
              for (PlasticMethod method : 
plasticClass.getMethodsWithAnnotation(ExceptionDisplay.class))
              {
                     method.addAdvice(this.advice);
              }
       }
}

-----------------------------
package myproject.tapestry.services;

public class MyProjectModule
{
public static void bind(ServiceBinder binder)
{
       binder.bind(ExceptionDisplayMethodAdvice.class, 
ExceptionDisplayMethodAdviceImpl.class);
}
}
-----------------------------

Reply via email to