Discussion:
Access to MessageResource from action.
Michał Letyński
2007-05-22 06:46:15 UTC
Permalink
How to do this in struts 2 ?
In struts 1 i had:
MessageResources resources = (MessageResources)
getServlet().getServletContext().getAttribute(org.apache.struts.Globals.MESSAGES_KEY);
Michał Letyński
2007-05-22 07:06:54 UTC
Permalink
Post by Michał Letyński
How to do this in struts 2 ?
MessageResources resources = (MessageResources)
getServlet().getServletContext().getAttribute(org.apache.struts.Globals.MESSAGES_KEY);
---------------------------------------------------------------------
Sorry for that queestion, instead of getServlet()i need
ServletActionContext.
Nuwan Chandrasoma
2007-05-22 13:01:52 UTC
Permalink
hi,

ServletActionContext.getServletContext();

Thanks,

Nuwan

----- Original Message -----
From: "Michał Letyński" <***@consol.pl>
To: "Struts Users Mailing List" <***@struts.apache.org>
Sent: Tuesday, May 22, 2007 7:06 AM
Subject: Re: Access to MessageResource from action.
Post by Michał Letyński
Post by Michał Letyński
How to do this in struts 2 ?
MessageResources resources = (MessageResources)
getServlet().getServletContext().getAttribute(org.apache.struts.Globals.MESSAGES_KEY);
---------------------------------------------------------------------
Sorry for that queestion, instead of getServlet()i need
ServletActionContext.
---------------------------------------------------------------------
Zoran Avtarovski
2007-05-22 11:41:03 UTC
Permalink
Out of curiosity, why wouldn't you use:

ResourceBundle.getBundle(propFile, Locale, getClass().getClassLoader());


Z.
Post by Nuwan Chandrasoma
hi,
ServletActionContext.getServletContext();
Thanks,
Nuwan
----- Original Message -----
Sent: Tuesday, May 22, 2007 7:06 AM
Subject: Re: Access to MessageResource from action.
Post by Michał Letyński
Post by Michał Letyński
How to do this in struts 2 ?
MessageResources resources = (MessageResources)
getServlet().getServletContext().getAttribute(org.apache.struts.Globals.MESS
AGES_KEY);
---------------------------------------------------------------------
Sorry for that queestion, instead of getServlet()i need
ServletActionContext.
---------------------------------------------------------------------
---------------------------------------------------------------------
Jeromy Evans
2007-05-22 14:01:08 UTC
Permalink
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
Post by Michał Letyński
Post by Michał Letyński
How to do this in struts 2 ?
MessageResources resources = (MessageResources)
getServlet().getServletContext().getAttribute(org.apache.struts.Globals.MESSAGES_KEY);
---------------------------------------------------------------------
Sorry for that queestion, instead of getServlet()i need
ServletActionContext.
---------------------------------------------------------------------
Loading...