Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If interceptors are not specified, the default stack is applied.

InterceptorRef(s) annotation

Interceptor can be specified at the method level, using the Action annotation or at the class level using InterceptorRefs. Interceptors specified at the class level will be to all actions defined on that class. In the following example:

Code Block
titlecom.example.actions.HelloWorld
borderStylesolid

package com.example.actions;

import com.opensymphony.xwork2.ActionSupport; 
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;

@InterceptorRefs({
    @InterceptorRef("interceptor-1"),
    @InterceptorRef("defaultStack")
})
public class HelloWorld extends ActionSupport {
  @Action(value="action1", interceptorRefs=@InterceptorRef("validation"))
  public String execute() {
    return SUCCESS;
  }

  @Action(value="action2")
  public String doSomething() {
    return SUCCESS;
  }
}

The following interceptors will be applied to "action1": "interceptor-1", all interceptors from "defaultStack", "validation".
All interceptors from "defaultStack" will be applied to "action2".

Result(s) annotation

The Convention plugin allows action classes to define different results for an action. Results fall into two categories, global and local. Global results are shared across all actions defined within the action class. These results are defined as annotations on the action class. Local results apply only to the action method they are defined on. Here is an example of the different types of result annotations:

...