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

On Wed, May 12, 2010 at 4:57 AM, Andy Law <andy....@roslin.ed.ac.uk> wrote:
>
> All,
>
> Apologies if this would be better asked in a Spring forum. If so, I would
> appreciate guidance as to which one/where.
>
> I have a Struts2 application with around 30 actions. Most inherit from a
> common base class. We have configured the system to start to use Spring to
> inject certain things into certain places. This seems to work well and we
> are all currently happy bunnies.
>
> A new requirement means that we need to have available across pretty much
> every action a separate, independent bean that carries information that may
> (or may not) need to be displayed on the resulting web-pages. I am wondering
> what the best way is to make this bean available to each JSP.
>
> I'm happy with injecting certain beans into certain actions, but I'm not
> clear what I should be injecting *this* bean into. Ideally it should just
> pop into existence and be available to the JSPs without the Actions even
> being aware that it is there. It's not part of the business logic and is
> purely informational. If I have to make it available through the Actions
> then I would *like* to be able to inject it into the common base class with
> a single configuration and have that work automatically for all sub-classes
> (and this would be a useful trick for some other places in the application)
> but that does not seem to be possible unless I'm missing a trick?
>
> How should I configure this, please?
>
> Later,
>
> Andy
> --
> View this message in context: 
> http://old.nabble.com/Some-Spring-Struts-questions-tp28533505p28533505.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>



-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

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

Reply via email to