You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Reumann <r...@reumann.net> on 2003/03/08 05:00:10 UTC

[Q] Getting a handle to MessageResources in an ActionForm?

I normally use the DynaValidator stuff so I haven't run into this, but
I'm writing up a lesson using a standard ActionForm with a validate
method.

In the validate method I have as an example:

if ( getName() == null || getName().length() < 1 ) {
    errors.add("name",new ActionError("error.name.required"));
}

But what if I wanted to set up a global.required and wanted to pass in
"Name." I of course understand I could do:

if ( getName() == null || getName().length() < 1 ) {
    errors.add("name",new ActionError("error.name.required", "Name"));
}

but this creates problems if you want internationalization since you are
hardcoding in the word "Name." I'd like to do:

errors.add("name",new ActionError("error.name.required",
messages.getMessage("name") ));

but I'm blanking on a way to get a handle to MessageResources within an
ActionForm. 

Within in Action I can see how to do it ( getResources( request ) ) but
I can't see how to get this in an AcionForm since Action getReources is
protected in the actions package.

Thanks for any help,

(I did search the archives and someone else asked this but I didn't see
an answer posted).

-- 
Rick

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


Re: [Q] Getting a handle to MessageResources in an ActionForm?

Posted by Rick Reumann <r...@reumann.net>.
On Fri, Mar 07,'03 (11:00 PM GMT-0500), Rick wrote: 
 
> 
> But what if I wanted to set up a global.required and wanted to pass in
> "Name." I of course understand I could do:
> 
> if ( getName() == null || getName().length() < 1 ) {
>     errors.add("name",new ActionError("error.name.required", "Name"));
> }

Of course this global message key would be something like
"global.error.required" (I forgot to fix that in my cut and paste for
this post).

Still the same question... How do I get access to MessageResources in an
ActionForm.

Thanks,


-- 
Rick

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