You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Michał Letyński <ml...@consol.pl> on 2007/05/22 08:46:15 UTC
Access to MessageResource from action.
How to do this in struts 2 ?
In struts 1 i had:
MessageResources resources = (MessageResources)
getServlet().getServletContext().getAttribute(org.apache.struts.Globals.MESSAGES_KEY);
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Access to MessageResource from action.
Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Hi Michał,
Although that approach will work, if you're creating a new message
resource bundle you may prefer the new Struts2 approach described at
http://struts.apache.org/2.x/docs/localization.html and demonstrated at
http://www.planetstruts.org/struts2-mailreader/Tour.do.
Essentially you can define a message resource per action and don't need
to write any code to use it. If your action extends ActionSupport the
resources are available through getText("some.key") and <s:text
name="some.key" />. It works well.
Additionally, if your action implements ServletContextAware, the
ServletContext will be injected into your action by the
ServletConfigInterceptor. That's a nice alternative to your call to the
static method ServletActionContext.getServletContext();
cheers,
Jeromy Evans
Michał Letyński wrote:
> Michał Letyński napisał(a):
>> How to do this in struts 2 ?
>> In struts 1 i had:
>> MessageResources resources = (MessageResources)
>> getServlet().getServletContext().getAttribute(org.apache.struts.Globals.MESSAGES_KEY);
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
> Sorry for that queestion, instead of getServlet()i need
> ServletActionContext.
>
> ---------------------------------------------------------------------
> 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
Re: Access to MessageResource from action.
Posted by Zoran Avtarovski <zo...@sparecreative.com>.
Out of curiosity, why wouldn't you use:
ResourceBundle.getBundle(propFile, Locale, getClass().getClassLoader());
Z.
> hi,
>
> ServletActionContext.getServletContext();
>
> Thanks,
>
> Nuwan
>
> ----- Original Message -----
> From: "Michał Letyński" <ml...@consol.pl>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Tuesday, May 22, 2007 7:06 AM
> Subject: Re: Access to MessageResource from action.
>
>
>> Michał Letyński napisał(a):
>>> How to do this in struts 2 ?
>>> In struts 1 i had:
>>> MessageResources resources = (MessageResources)
>>> getServlet().getServletContext().getAttribute(org.apache.struts.Globals.MESS
>>> AGES_KEY);
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>> Sorry for that queestion, instead of getServlet()i need
>> ServletActionContext.
>>
>> ---------------------------------------------------------------------
>> 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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Access to MessageResource from action.
Posted by Nuwan Chandrasoma <my...@gmail.com>.
hi,
ServletActionContext.getServletContext();
Thanks,
Nuwan
----- Original Message -----
From: "Michał Letyński" <ml...@consol.pl>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Tuesday, May 22, 2007 7:06 AM
Subject: Re: Access to MessageResource from action.
> Michał Letyński napisał(a):
>> How to do this in struts 2 ?
>> In struts 1 i had:
>> MessageResources resources = (MessageResources)
>> getServlet().getServletContext().getAttribute(org.apache.struts.Globals.MESSAGES_KEY);
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
> Sorry for that queestion, instead of getServlet()i need
> ServletActionContext.
>
> ---------------------------------------------------------------------
> 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
Re: Access to MessageResource from action.
Posted by Michał Letyński <ml...@consol.pl>.
Michał Letyński napisał(a):
> How to do this in struts 2 ?
> In struts 1 i had:
> MessageResources resources = (MessageResources)
> getServlet().getServletContext().getAttribute(org.apache.struts.Globals.MESSAGES_KEY);
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
Sorry for that queestion, instead of getServlet()i need
ServletActionContext.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org