Apache Struts 2 Documentation > Home > Guides > Core Developers Guide > Pre Result Listener |

Apache Struts 2 Documentation
Pre Result Listener
Edit Page Browse Space Add Page Add News
Added by tm_jee, last edited by tm_jee on Oct 13, 2006 (view change)

PreResultListener is provided to allow alteration / cause influence on a particular action invocation (eg. maybe its Result object, switching to a different result, the Action object itself etc) before the Result is being executed. This could be done at the Action object or at the Interceptor itself.

## Examples

### Action object

    public class MyAction extends ActionSupport {
         ...
         public String execute() throws Exception {
             ActionInvocation invocation = ActionContext.getActionInvocation();
             invocation.addPreResultListener(new PreResultListener() {
                  public void beforeResult(ActionInvocation invocation,
                                           String resultCode) {
                      // perform operation necessary before Result execution
                  }
             });
         }
         ...
      }

### Interceptor

    public class MyInterceptor extends AbstractInterceptor {
         ...
          public String intercept(ActionInvocation invocation) throws Exception {
             invocation.addPreResultListener(new PreResultListener() {
                  public void beforeResult(ActionInvocation invocation,
                                           String resultCode) {
                      // perform operation necessary before Result execution
                  }
             });
          }
         ...
      }