Thursday, March 5, 2009

Struts interceptor code for execution before and after action or result

The code to be executed before and after action class execution needs to be written in the intercept
method of the interceptor.

<code before action invocation>

String result= ActionInvocation(object).invoke();
(By this time the display page is already constructed in memory)

<code after action invocation>

return result

In the above case though the <code after action invocation> will execute it will not be able to modify
the values in the resulting page.

This is beacause the flow is as follows

<Interceptor b4 action> --> Action --> Result Formed(In memory) --> <Interceptor after action>

So the modifications made after the interceptor will only be seen in the next to next pages;

If the interceptor needs to modify the values which is need in the immediate next page
then we need to use

ActionInvocation(object).invokeActionOnly();

this will ensure that the post processing is done before the result object is constructed.Hence ensuring that the
change in the post processing of the interceptor is visible in the next pages

No comments:

 
Free Domain Names @ .co.nr!