You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kyle Robinson <KR...@pangaeainc.com> on 2001/06/04 21:48:29 UTC

How do I Internationalize ActionError parameter values?

Hey,
 
Looking through the archive I found a couple of notes about
internationalizing the ActionError parameters.  I'm talking about the
following:
 
public ActionError(java.lang.String key,

                   java.lang.Object value0,

                   java.lang.Object value1)

Construct an action error with the specified replacement values. 




Parameters: 

key - Message key for this error message 

value0 - First replacement value 

value1 - Second replacement value

 
What I want to do is pass in keys from the properties file into the second
and third parameter.  Specifically I want to pass in the prompt keys to
display to the user the fields that are in error.
 
One possible solution proposed was by Craig as follows:
 
The java.text.MessageFormat class (which is how Struts is doing the
substitution) does not support internationalizing the replacement
parameters directly.  But how about doing this in two steps?

* Look up the internationalized replacement value from
  a MessageResources bundle

* Use the returned String as the replacement value in the
  ultimate message.

However, I need to get the locale somehow.  It seems alot easier to just
override ActionError to accept keys as parameters.  Has anyone overridden
the ActionError class to accept "java.lang.String key" parameters instead of
"java.lang.Object value0"?

Kyle Robinson 
Systems Consultant 
Pangaea Systems Inc. 
(250) 360-0111

"Work joyfully and peacefully, knowing that right thoughts and right efforts
inevitably bring about right results." - James Allen 

 

RE: How do I Internationalize ActionError parameter values?

Posted by "Deadman, Hal" <ha...@tallan.com>.
Getting the locale object is easy. If you are in an Action perform method,
just call:

getLocale(request);

If you are not in the Action class, you can do what that method does,

Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY);
if (locale == null)
     locale = Locale.getDefault();

-----Original Message-----
From: Kyle Robinson [mailto:KRobinson@pangaeainc.com]
Sent: Monday, June 04, 2001 3:48 PM
To: Struts (E-mail)
Subject: How do I Internationalize ActionError parameter values?


Hey,

Looking through the archive I found a couple of notes about
internationalizing the ActionError parameters.  I'm talking about the
following:

public ActionError(java.lang.String key,
                   java.lang.Object value0,
                   java.lang.Object value1)
Construct an action error with the specified replacement values.
Parameters:
key - Message key for this error message
value0 - First replacement value
value1 - Second replacement value

What I want to do is pass in keys from the properties file into the second
and third parameter.  Specifically I want to pass in the prompt keys to
display to the user the fields that are in error.

One possible solution proposed was by Craig as follows:

The java.text.MessageFormat class (which is how Struts is doing the
substitution) does not support internationalizing the replacement
parameters directly.  But how about doing this in two steps?

* Look up the internationalized replacement value from
  a MessageResources bundle

* Use the returned String as the replacement value in the
  ultimate message.

However, I need to get the locale somehow.  It seems alot easier to just
override ActionError to accept keys as parameters.  Has anyone overridden
the ActionError class to accept "java.lang.String key" parameters instead of
"java.lang.Object value0"?
Kyle Robinson
Systems Consultant
Pangaea Systems Inc.
(250) 360-0111
"Work joyfully and peacefully, knowing that right thoughts and right efforts
inevitably bring about right results." - James Allen