You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Peter Theissen <pe...@web.de> on 2008/04/10 12:08:58 UTC

Again: question to interceptors

Hello,

first of all thanks for all your previous answers. Somehow,
I got the interceptor working for the simplest case, but
honestly I still dont know exactly why. Maybe it was a
caching issue.

Now I have some questions:

I have the "SimpleInterceptor":
 >>>
public String intercept(ActionInvocation invocation) throws Exception {
  System.out.println("The action is being intercepted!");
  return invocation.invoke();       
  //return Action.SUCCESS; (**)
}
<<<

and the struts.xml contains:
 >>>
<action name="listRegistrationsWaiting" 
class="registrationWaitingAction" method="execute">
  <result>pages/list.jsp</result>
  <result name="input">pages/list.jsp</result>
  <interceptor-ref name="simpleInterceptor"/>           
</action>
<<<

When I comment in (**) instead of the return,
the result is not displayed (list.jsp) is not invoked.
I dont understand why, since the interceptor should
be called as the LAST step as far as I understand the
doc?! Therefore, there should be no influence of
the interceptor at the result at all!

But obvously, Im misunderstanding something, since I found
out that it works, when I just call return invocation.invoke();
But also in this case I wounder why the interceptor is called
BEFORE the DB Access (I can see that on the console),
since the interceptor is provided as the LAST part of the
action.

Thanks for your help
Peter



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Again: question to interceptors

Posted by Peter Theissen <pe...@web.de>.
Hi all, dear Ralf,

thanks a lot for your answer it was really helpful.
Honestly, I didnt understand the call-stack-principle
behind the interceptors at all. So your hint:
"To understand recursion, you must understand recursion"
was a good one and also this picture:
[1] http://struts.apache.org/2.0.11.1/docs/big-picture.html
I already knew that design from the event handling of
a Javascript API (Map24 AJAX API)

However, what I thought, was one has to determine the
order in that the interceptors are called, in the action tag:
all interceptors that are before the result are also called
before the action, then the action is called, then the result
and those the interceptors are called, which are written AFTER
the result tags. OK, in retrospect my idea was also not
so intelligent ;-)

Thx & best regards
Peter



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Again: question to interceptors

Posted by Ralf Fischer <th...@googlemail.com>.
Hi Peter,

On Thu, Apr 10, 2008 at 12:08 PM, Peter Theissen <pe...@web.de> wrote:
<snip />
>  I have the "SimpleInterceptor":
>  >>>
>  public String intercept(ActionInvocation invocation) throws Exception {
>   System.out.println("The action is being intercepted!");
>   return invocation.invoke();        //return Action.SUCCESS; (**)
>  }
>  <<<

You 'usually' don't return anything else from the intercept method
despite the return code of the action invocation itself. Anyway the
return of your interceptor leads back to the action invocation, which
then puts the resulting success-String into a local variable and
returns null. End of processing. So neither action nor result are
executed, as there never is a call to actionInvocation.invoke() at the
end of your interceptor stack, which whould do this. You only
understand what a recursion is, when you've understood recursion ;-)

>  and the struts.xml contains:
>  >>>
>  <action name="listRegistrationsWaiting" class="registrationWaitingAction"
> method="execute">
>   <result>pages/list.jsp</result>
>   <result name="input">pages/list.jsp</result>
>   <interceptor-ref name="simpleInterceptor"/>           </action>
>  <<<

You know this leaves you with only ONE interceptor on your interceptor
stack, the default stack is completely omitted! Means no configuration
parameters or URL parameters injected into your action, and lots of
other stuff you miss. Try something like

<action name="foo" class="org.bar.Foo">
  <result>/foo.jsp</result>
  <interceptor-ref name="defaultStack" />
  <interceptor-ref name="simpleInterceptor" />
</action>

>  When I comment in (**) instead of the return,
>  the result is not displayed (list.jsp) is not invoked.
>  I dont understand why, since the interceptor should
>  be called as the LAST step as far as I understand the
>  doc?! Therefore, there should be no influence of
>  the interceptor at the result at all!

Nope. actionInvocation.invoke() calls the next intercepter on the
interceptor stack until there are no more interceptors. THEN the call
to actionInvocation.invoke() from the last interceptor on the stack
invokes the action. Thus in your example above the action never should
be called.

>  But obvously, Im misunderstanding something, since I found
>  out that it works, when I just call return invocation.invoke();
>  But also in this case I wounder why the interceptor is called
>  BEFORE the DB Access (I can see that on the console),
>  since the interceptor is provided as the LAST part of the
>  action.

Check out some more docs in the wiki, especially take a look at the
big picture[1] and interceptors[2].

Cheers,
-Ralf


[1] http://struts.apache.org/2.0.11.1/docs/big-picture.html
[2] http://struts.apache.org/2.x/docs/interceptors.html

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org