You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Niesen, Nathan" <na...@objectfx.com> on 2003/04/10 19:59:50 UTC

RE: Access application resource bundle from an ActionForm

Does anyone know how to do this now that ActionServlet.getResources() is
deprecated?

Thanks, Nathan.

Nathan A. Niesen
Application Developer
ObjectFX Corporation
10 Second St NE, Suite 400
Minneapolis, MN  55413
612-312-2002 x2633
mailto:Nathan.Niesen@ObjectFX.com
www.objectfx.com


Date: Wed, 05 Dec 2001 10:24:51 -0700
From: Bruce Geerdes <br...@sun.com>
Subject: Access application resource bundle from an ActionForm
Content-Type: text/plain; charset=us-ascii

Try:

        MessageResources resources = getServlet().getResources();
        resources.getMessage("emailAddressLabel");

If your bundle is localized, you'll have to get the locale separately
and pass that on to the getMessage.

        Locale loc = (Locale)request.getSession().getAttribute(
                            org.apache.struts.action.Action.LOCALE_KEY);
        resources.getMessage(loc, "emailAddressLabel");

Cheers,
Bruce


"Silvert, Stan" wrote:
> 
> I need to access the Struts application resource bundle from an
ActionForm.
> Here is why:
> 
> During validation, I want to check for a required field such as email
> address.   In my system, "Email Address" is always referred to from a
> resource bundle so that I can localize properly.
> 
> So, my English language resource bundle looks something like this:
> 
> requiredFieldError = <li>{0} is a required field</li>
> emailAddress = Email Address
> 
> In my ActionForm validate(mapping, request) method, I would like to say
> something like:
> 
> ActionErrors errors = new ActionErrors();
> if (notFilledIn(this.emailAddress)) {
>    errors.add("emailAddress",
>                   new ActionError("requiredFieldError", !!! resource that
> "emailAddress" points to !!!);
> }
> 
> The question is, how do I get at the resource that "emailAddressLabel"
> points to, so that I can localize my ActionError?
> 
> My solution so far is to subclass ActionServlet and make the
> MessageResources available as a static member.  But, this seems like a
hack.
> 
> Is there a better way to get to the MessageResources from an ActionForm?
> 
> Thanks in advance for your help,
> 
> Stan Silvert
> 
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



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


RE: Access application resource bundle from an ActionForm

Posted by Mike Jasnowski <mj...@bea.com>.
I think MessageResources now has a static method to get an instance of this
now.

-----Original Message-----
From: Niesen, Nathan [mailto:nathan.niesen@objectfx.com]
Sent: Thursday, April 10, 2003 2:00 PM
To: 'bruce.geerdes@sun.com'; Struts Users Mailing List (E-mail)
Subject: RE: Access application resource bundle from an ActionForm


Does anyone know how to do this now that ActionServlet.getResources() is
deprecated?

Thanks, Nathan.

Nathan A. Niesen
Application Developer
ObjectFX Corporation
10 Second St NE, Suite 400
Minneapolis, MN  55413
612-312-2002 x2633
mailto:Nathan.Niesen@ObjectFX.com
www.objectfx.com


Date: Wed, 05 Dec 2001 10:24:51 -0700
From: Bruce Geerdes <br...@sun.com>
Subject: Access application resource bundle from an ActionForm
Content-Type: text/plain; charset=us-ascii

Try:

        MessageResources resources = getServlet().getResources();
        resources.getMessage("emailAddressLabel");

If your bundle is localized, you'll have to get the locale separately
and pass that on to the getMessage.

        Locale loc = (Locale)request.getSession().getAttribute(
                            org.apache.struts.action.Action.LOCALE_KEY);
        resources.getMessage(loc, "emailAddressLabel");

Cheers,
Bruce


"Silvert, Stan" wrote:
>
> I need to access the Struts application resource bundle from an
ActionForm.
> Here is why:
>
> During validation, I want to check for a required field such as email
> address.   In my system, "Email Address" is always referred to from a
> resource bundle so that I can localize properly.
>
> So, my English language resource bundle looks something like this:
>
> requiredFieldError = <li>{0} is a required field</li>
> emailAddress = Email Address
>
> In my ActionForm validate(mapping, request) method, I would like to say
> something like:
>
> ActionErrors errors = new ActionErrors();
> if (notFilledIn(this.emailAddress)) {
>    errors.add("emailAddress",
>                   new ActionError("requiredFieldError", !!! resource that
> "emailAddress" points to !!!);
> }
>
> The question is, how do I get at the resource that "emailAddressLabel"
> points to, so that I can localize my ActionError?
>
> My solution so far is to subclass ActionServlet and make the
> MessageResources available as a static member.  But, this seems like a
hack.
>
> Is there a better way to get to the MessageResources from an ActionForm?
>
> Thanks in advance for your help,
>
> Stan Silvert
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



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



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