JavaScud | Forum | JIRA | Blog |
  Dashboard > WebWork2文档中文化计划 > ... > J2SE 5 Support > AnnotationWorkflowInterceptor
  WebWork2文档中文化计划 Log In View a printable version of the current page.  
  AnnotationWorkflowInterceptor
Added by scud, last edited by 黑灵 on May 08, 2006  (view change)
Labels: 
(None)

AnnotationWorkflowInterceptor 拦截器

调用action中的任何被标注的方法, 它支持一下特定的方法:

  • @Before - 在action方法之前调用. 如果没有返回null, 则它的返回值作为action的结果码.
  • @BeforeResult - 在action方法之后,result执行之前调用.
  • @After - 在action方法和result执行之后被调用.

一个类中可以有多个方法有同样的标注,但是执行的顺序不一定. 尽管如此, 父类中的Before标注方法会在子类中Before标注方法之前调用,而After标注方法会在子类的After标注方法之后调用.

例子

public class BaseAnnotatedAction {
 	protected String log = "";

 	@Before
 	public String baseBefore() {
 		log = log + "baseBefore-";
 		return null;
 	}
 }

 public class AnnotatedAction extends BaseAnnotatedAction {
 	@Before
 	public String before() {
 		log = log + "before";
 		return null;
 	}

 	public String execute() {
 		log = log + "-execute";
 		return Action.SUCCESS;
 	}

 	@BeforeResult
 	public void beforeResult() throws Exception {
 		log = log +"-beforeResult";
 	}

 	@After
 	public void after() {
 		log = log + "-after";
 	}
 }

配置xwork.xml把其中的PrepareInterceptor替换为AnnotationWorkflowInterceptor:

<interceptor-stack name="annotatedStack">
<interceptor-ref name="static-params"/>
<interceptor-ref name="params"/>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="annotationInterceptor"/>
</interceptor-stack>

下面这一个AnnotatedAction,加上了AnnotationWorkflowInterceptor拦截器

<action name="AnnotatedAction" class="com.examples.AnnotatedAction">
   <interceptor-ref name="annotationInterceptor"/>
   <result name="success" type="freemarker">good_result.ftl</result>
</action>

随着这个拦截器的生效,AnnotatedAction中方法以后,log实例的值为baseBefore-before-execute-beforeResult-after

Site running on a free Atlassian Confluence Open Source Project License granted to WebWork China. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.3 Build:#808 May 29, 2007) - Bug/feature request - Contact Administrators