Java Reference
In-Depth Information
@After(stages={LifecycleStage.EventHandling,LifecycleStage.RequestComplete})
private void interceptor2() {
// do something after event handling and also after request complete
}
@Before
protected Resolution interceptor3() {
// do something before the default stage: event handling
if (someCondition) {
// interrupt the flow by returning a resolution
// event handling will not execute in this case
return new RedirectResolution(...);
}
// do not interrupt the flow
return null ;
}
@Before
@After
public int interceptor4() {
// Do something before and after event handling
// Any returned values that are not resolutions are ignored
return 42;
}
@Before(on="save")
public int interceptor5() {
// Do something before event handling, but only for the "save" event
}
Notice the following aspects illustrated in the previous examples:
• Interceptor methods can be named anything, have any access
modifier ( private , public , and so on), return anything (more on this
in the next point), but cannot accept any parameters.
• The method can be void or return any type. If the method returns
a resolution, the life-cycle sequence is interrupted, and that reso-
lution is executed. Any other returned value is ignored.
• You specify which life-cycle stages to intercept in the stages= attri-
bute of @Before and @After . The default stage is EventHandling .
@Before cannot be run before RequestInit or ActionBeanResolution ,
and @After cannot be run after RequestInit , all for the same reason:
the action bean does not yet exist at those points in time!
• A method can be annotated with both @Before and @After .
• We can restrict an interceptor method to specific events by indi-
cating the event names in the on= attribute, either positively as in
on={"save", "update"} or negatively as in on="!delete" .
 
 
Search WWH ::




Custom Search