PreResultListener is a little hook that results in a callback being made to it before the actual result is to be executed but after the action invocation took place.

How does it works

  • start request
    • begin of interception 1
      • begin of interception 2
        • action
        • pre-result-listener kicks in
        • execution of result
      • end of interception 2
    • end of interception 1
  • end request

How to add PreResultListener in my code?

Through Interceptor

public class MyInterceptor implements Interceptor {
   ...
   public String intercept(ActionInvocation invocation) throws Exception {
      // we could hook up PreResultListener here
      invocation.addPreResultListener(new PreResultListener() { 
          public void beforeResult(ActionInvocation invocation, String result) {
             ....
          }
      });
   }
   ...
 }

Through Action

public class MyAction extends ActionSupport {
    public String execute() throws Exception {
         ActionContext.getContext().getActionInvocation().addPreResultListener() { 
              new PreResultListener() {
                  public void beforeResult(ActionInvocation invocation, String result) {
                     ....
                  }
              }
         };
    }
 }