Apache Struts 2 Documentation > Home > Guides > Core Developers Guide > Pre Result Listener |
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.
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 } }); } ... }
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 } }); } ... }