Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Yes, you can access the ResultConfig objects before the Action executes, and you can access the final Result object using a PreResultListener.

Accessing the ResultConfig Objects

If you need to work with the set of ResultConfigs before the Action executes, you can use an Interceptor to process the Map returned by getResults.

Code Block
java
java
public class MyInterceptor implements Interceptor {
  // ...
  public String intercept(ActionInvocation invocation) throws Exception {
    Map resultsMap = invocation.getProxy().getConfig().getResults();

      // do something with ResultConfig in map

    return invocation.invoke();
  }
  // ...
}

If you are writing against Java 5, you could use a generic when obtain the map.

Code Block
java
java
Map<String, ResultConfig> resultsMap = invocation.getProxy().getConfig().getResults();

Adding a PreResultListener

If you need to work with the final Result object before it is executed, you can use an Interceptor to register a PreResultListener. The code example creates a PreResultListener as an anonymous inner class.

Code Block
java
java
public class MyInterceptor implements Interceptor {
  // ...
  public String intercept(ActionInvocation invocation) throws Exception {

    invocation.addPreResultListener(new PreResultListener() {

      public void beforeResult(ActionInvocation invocation, String resultCode) {
        Map resultsMap = invocation.getProxy().getConfig().getResults();
        ResultConfig finalResultConfig = resultsMap.get(resultCode);

          // do something interesting with the 'to-be' executed result

        }

      });

    return invocation.invoke();
  }
  // ...
}

If you are writing against Java 5, you could use a generic when obtain the map.

Code Block
java
java
Map<String, ResultConfig> resultsMap = invocation.getProxy().getConfig().getResults();