WebWork2.2で以下のアノテーションサポートが追加されました。
- Interceptor Annotations
- Validation Annotations
- Type Conversion Annotations
下の2つは設定ファイルで書いた方が楽だと思いますが(^^;、Interceptor Annotationsは便利なので紹介します。
これはアノテーションによって、Action,Resultの前後で行う処理を指定する機能になります。
設定(xwork.xml)
AnnotationWorkflowInterceptorを定義してActionに設定します。
<interceptors> <interceptor name="annotationWorkflow" class="com.opensymphony.xwork.interceptor.annotations.AnnotationWorkflowInterceptor"/> </interceptors> <action name="annotation" class="ww2.examples.event.AnnotationAction"> <interceptor-ref name="annotationWorkflow"/> </action>
AnnotationAction
アノテーションは@Before,@BeforeResult,@Afterの3つありそれぞれ以下のタイミングで実行されます。
public class AnnotationAction extends ActionSupport { @Override public String execute() { System.out.println("execute"); return SUCCESS; } @Before public void before() { System.out.println("before"); } @BeforeResult public void beforeResult() { System.out.println("beforeResult"); } @After public void after() { System.out.println("after"); } }