On 12/18/06, Jon Wilmoth <[EMAIL PROTECTED]> wrote:
I'm working on a custom S2 Interceptor and I'm not sure what the best way to interact
with the session and/or other Interceptors for that matter is. First the session. I
read http://struts.apache.org/2.x/docs/how-do-we-get-access-to-the-session.html and I
tried applying the concept of using a SessionAware dependency injection on my custom
interceptor (i.e. public class MyCustomInterceptor extends AbstractInterceptor implements
SessionAware). I added the "servlet-config" interceptor to my interceptor
stack prior to my custom interceptor. Unfortunately, the ServletConfigInterceptor class
only injects dependencies on the action. This seems me that the only *current* way for
an interceptor to interact with the session is through
ServletActionContext.getRequest().getSession();
Yep, ServletActionContext.getRequest().getSession() is currently the
best way to do this.
Along the same train-of-thought, I'm also working on another custom interceptor
that uses the output of a previous custom interceptor to do it's work. After
coming to the realization above I thought I might be able to use the
ActionInvocation to get ahold of the downstream interceptors and check to see
if they implemented a dependency injection interface similar to SessionAware.
Unfortunately, one can only access the action via the ActionInvocation. Is the
lack of access to other interceptors within an interceptor intentional? Is it
bad to try and spread the notion of dependency injection on actions to
interceptors?
<interceptor-stack name="baseStack">
...
<interceptor-ref name="createSession"/>
<!-- populate SessionAware, XyzAware actions -->
<interceptor-ref name="servlet-config"/>
<!-- Custom interceptor to populate CurrentUserAware actions [and downstream
interceptors?] -->
<interceptor-ref name="currentUser"/>
<!-- Custom interceptor to load currentUser's preferences...implements
CurrentUserAware -->
<interceptor-ref name="userPrefs"/>
...
</interceptor-stack>
Hmm...do we really need to add IoC to interceptors? What benefit
would this provide over storing and retrieving objects from the
ActionContext?
Don
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]