You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Gary Moore <ga...@clearridgeconsult.com> on 2009/10/03 16:40:44 UTC
[strut2] How to get ServletActionContext
Newbie question here.
In my struts1 apps stuff gets loaded into an application container on
start-up using ActionServlet, e.g.
servlet.getServletContext().setAttribute(
IConstants.APPLICATION_CONTAINER_KEY, app ); .
I'm trying to do the comparable in struts2 using a bean in
applicationContext.xml:
<bean id="apptainer"
class="com.clearridgeconsult.struts2.framework.AgricolaApplicationContainer"
>
<constructor-arg index="0"
value="/WEB-INF/config/NALTIndexConfig.xml"/>
<constructor-arg index="1"
value="/WEB-INF/config/AgricolaIndexConfig.xml"/>
</bean>
However, in the AgricolaApplicationContainer constructor,
ServletActionContext.getServletContext() is null. From seaching the
list archives, I've tried setting up a factory bean in
applicationContext.xml to make the servlet context available:
<bean id="contextFactory"
class="com.clearridgeconsult.struts2.framework.StrutsServletContextLoader"/>
<bean id="servletCtx" factory-bean="contextFactory"
factory-method="getServletContext"/>
<bean id="apptainer"
class="com.clearridgeconsult.struts2.framework.AgricolaApplicationContainer"
>
<constructor-arg index="0"
value="/WEB-INF/config/NALTIndexConfig.xml"/>
<constructor-arg index="1"
value="/WEB-INF/config/AgricolaIndexConfig.xml"/>
<constructor-arg index="2" ref="servletCtx"/>
</bean>
But, again, ServletActionContext.getServletContext() is null in the
contextFactory bean.
I'm know I'm missing some obvious point here, but how do you make
ServletActionContext made available?
Thanks,
Gary
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [strut2] How to get ServletActionContext
Posted by Gary Moore <ga...@clearridgeconsult.com>.
Uh, no sooner than I sent this query did I realize that adding
singleton="false" to the factory bean solves my problem.
Thanks
Gary
Gary Moore wrote:
> Newbie question here.
> In my struts1 apps stuff gets loaded into an application container on
> start-up using ActionServlet, e.g.
> servlet.getServletContext().setAttribute(
> IConstants.APPLICATION_CONTAINER_KEY, app ); .
>
> I'm trying to do the comparable in struts2 using a bean in
> applicationContext.xml:
>
> <bean id="apptainer"
> class="com.clearridgeconsult.struts2.framework.AgricolaApplicationContainer"
> >
> <constructor-arg index="0"
> value="/WEB-INF/config/NALTIndexConfig.xml"/>
> <constructor-arg index="1"
> value="/WEB-INF/config/AgricolaIndexConfig.xml"/>
> </bean>
>
> However, in the AgricolaApplicationContainer constructor,
> ServletActionContext.getServletContext() is null. From seaching the
> list archives, I've tried setting up a factory bean in
> applicationContext.xml to make the servlet context available:
>
> <bean id="contextFactory"
> class="com.clearridgeconsult.struts2.framework.StrutsServletContextLoader"/>
>
> <bean id="servletCtx" factory-bean="contextFactory"
> factory-method="getServletContext"/>
> <bean id="apptainer"
> class="com.clearridgeconsult.struts2.framework.AgricolaApplicationContainer"
> >
> <constructor-arg index="0"
> value="/WEB-INF/config/NALTIndexConfig.xml"/>
> <constructor-arg index="1"
> value="/WEB-INF/config/AgricolaIndexConfig.xml"/>
> <constructor-arg index="2" ref="servletCtx"/>
> </bean>
>
> But, again, ServletActionContext.getServletContext() is null in the
> contextFactory bean.
>
> I'm know I'm missing some obvious point here, but how do you make
> ServletActionContext made available?
>
> Thanks,
> Gary
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org