That would be my favoured route.

Wes, side question. Using the convention plugin can you modify the stack
in the xml file so you don't have to annotate the action itself? Or do
you still have to add the annotation with the interceptor put in?

James

-----Original Message-----
From: Wes Wannemacher [mailto:w...@wantii.com] 
Sent: 12 May 2010 14:33
To: Struts Users Mailing List
Subject: Re: Some Spring/Struts questions

I've seen a few responses, but I think the best way would be to write
an interceptor that places the bean into the session. Give it a known
name in the session, then you can use OGNL to access it... Here is a
quick example of the interceptor -

public class CustomInterceptor extends AbstractInterceptor {

    private SomeBeanGeneratingService someBeanGeneratingService;

    public String intercept(ActionInvocation invocation) throws
Exception {
       invocation.getSession().put("knownBeanName",
someBeanGeneratingService.getBean());
       return invocation.invoke();
    }

    public void setSomeBeanGeneratingService(SomeBeanGeneratingService
someBeanGeneratingService) {
        this.someBeanGeneratingService = someBeanGeneratingService;
    }
}

The benefit is using an interceptor is two-fold... One is that it's
pretty easy to unit test (compared to a Servlet Filter). Two is that
it can be spring-configured and spring-injected.

With this interceptor putting the bean into the session, you can
access the bean's values through OGNL. Here is an example s:property
tag retrieving some property -

<s:property value="%{#session.knownBeanName.someProperty}" />

Then, configure the interceptor and dependencies and put this
interceptor in your stack.

-Wes


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

Reply via email to