You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Gaet <ga...@free.fr> on 2005/12/01 09:02:50 UTC

Re: Parameter of ActionMessage...

Thanks Laurie,

It's exactly what I want but in fact I want to this in an ActionForm class.
And from and ActionForm, I can't access to getResources(..) method

How to achieve that in an ActionForm? is it possible?

Moreover, why to you define variable "locale" because you don't use it afterwhile...

Thank you very much!


 
  ----- Original Message ----- 
  From: Laurie Harper 
  To: user@struts.apache.org 
  Sent: Wednesday, November 30, 2005 11:36 PM
  Subject: Re: Parameter of ActionMessage...


  Gaet, ActionMessage doesn't support doing that lookup for you 
  automatically, but you can achieve what you want fairly easily:

     Locale locale = request.getLocale();
     String arg = getResources(request).getMessage("label.name");
     errors.add(ActionMessages.GLOBAL_MESSAGE,
       new ActionMessage("error.field.mandatory", arg));

  L.

  Gaet wrote:
  > Thanks Martin,
  > 
  > But I want to prepare the error message in the action tag because after, in my JSP, I loop over my errors with <html:messages> tag...
  > 
  > I don't know if I'm clear, but if I write the following code :
  > 
  > errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.field.mandatory","label.name"));
  > 
  > The result will be "The field label.name is mandatory"
  > 
  > but I would like 'label.name' replaced by its value defined in the resource properties....in order to have the result "The field Your Name is mandatory"
  > 
  > Thanks!
  >  
  >   ----- Original Message ----- 
  >   From: Martin Gainty 
  >   To: Struts Users Mailing List 
  >   Sent: Wednesday, November 30, 2005 4:47 PM
  >   Subject: Re: Parameter of ActionMessage...
  > 
  > 
  >   Bonjour gaet-
  > 
  >   the current implementation supports passing in parameters to the 
  >   bean:message tag at runtime e.g.
  >   <bean:message key="label.welcome" arg0="Firstname"/>
  > 
  >   which will produce
  >   The field 'Firstname' is mandatory
  > 
  >   HTH,
  >   M-
  >   ----- Original Message ----- 
  >   From: "Gaet" <ga...@free.fr>
  >   To: "Struts Users Mailing List" <us...@struts.apache.org>
  >   Sent: Wednesday, November 30, 2005 9:29 AM
  >   Subject: Re: Parameter of ActionMessage...
  > 
  > 
  >   > Nobody knows?
  >   >
  >   > Thanks for your time...
  >   >
  >   > ----- Original Message ----- 
  >   > From: Gaet
  >   > To: Mailing List Struts
  >   > Sent: Wednesday, November 30, 2005 12:14 PM
  >   > Subject: Parameter of ActionMessage...
  >   >
  >   >
  >   > Hi the list!
  >   >
  >   > Is it possible to give a key of the ressources.properties in parameter of 
  >   > an
  >   > ActionMessage?
  >   >
  >   > Example :
  >   > ----------
  >   >
  >   > # In Struts Action file
  >   >    errors.add(ActionMessages.GLOBAL_MESSAGE, new
  >   > ActionMessage("error.field.mandatory","label.name"));
  >   >
  >   > # In ressources.properties  file
  >   >    error.field.mandatory = The field '{0}' is mandatory
  >   >    label.name = Your Name
  >   >
  >   > I want the following result :  "The field 'Your Name' is mandatory"
  >   >
  >   >
  >   > Thanks for your help!
  >   >
  >   >
  >   > ---------------------------------------------------------------------
  >   > 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
  > 
  > 


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


Re: Parameter of ActionMessage...

Posted by Yujun Liang <yu...@acm.org>.
It can be done in ActionForm.

I assume you are building the ActionErrors when validate()ing the
ActionForm, you have access to request object, you can use a Singleton
ResourceManager to locate the locale aware ResourceBundle, or
MessageResources in Struts term.

Regards

On 12/2/05, Laurie Harper <la...@holoweb.net> wrote:
>
> Gaet wrote:
> > Thanks Laurie,
> >
> > It's exactly what I want but in fact I want to this in an ActionForm
> class.
> > And from and ActionForm, I can't access to getResources(..) method
> >
> > How to achieve that in an ActionForm? is it possible?
>
> Hmm, in that case you may be out of luck; ActionMessage works by storing
> resource keys which then get resolved (looked up in a resource bundle)
> when the message is rendered. I'm not sure there's a way to get a
> resource bundle from an ActionForm instance -- unless you pass in a
> reference to the appropriate bundle in a setup action and store the form
> bean in session scope so the reference is still valid during subsequent
> requests, when you need to reference it.
>
> > Moreover, why to you define variable "locale" because you don't use it
> afterwhile...
>
> Oops, I simplified the example code I posted and that was a left-over.
>
> L.
>
> >
> > Thank you very much!
> >
> >
> >
> >   ----- Original Message -----
> >   From: Laurie Harper
> >   To: user@struts.apache.org
> >   Sent: Wednesday, November 30, 2005 11:36 PM
> >   Subject: Re: Parameter of ActionMessage...
> >
> >
> >   Gaet, ActionMessage doesn't support doing that lookup for you
> >   automatically, but you can achieve what you want fairly easily:
> >
> >      Locale locale = request.getLocale();
> >      String arg = getResources(request).getMessage("label.name");
> >      errors.add(ActionMessages.GLOBAL_MESSAGE,
> >        new ActionMessage("error.field.mandatory", arg));
> >
> >   L.
> >
> >   Gaet wrote:
> >   > Thanks Martin,
> >   >
> >   > But I want to prepare the error message in the action tag because
> after, in my JSP, I loop over my errors with <html:messages> tag...
> >   >
> >   > I don't know if I'm clear, but if I write the following code :
> >   >
> >   > errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("
> error.field.mandatory","label.name"));
> >   >
> >   > The result will be "The field label.name is mandatory"
> >   >
> >   > but I would like 'label.name' replaced by its value defined in the
> resource properties....in order to have the result "The field Your Name is
> mandatory"
> >   >
> >   > Thanks!
> >   >
> >   >   ----- Original Message -----
> >   >   From: Martin Gainty
> >   >   To: Struts Users Mailing List
> >   >   Sent: Wednesday, November 30, 2005 4:47 PM
> >   >   Subject: Re: Parameter of ActionMessage...
> >   >
> >   >
> >   >   Bonjour gaet-
> >   >
> >   >   the current implementation supports passing in parameters to the
> >   >   bean:message tag at runtime e.g.
> >   >   <bean:message key="label.welcome" arg0="Firstname"/>
> >   >
> >   >   which will produce
> >   >   The field 'Firstname' is mandatory
> >   >
> >   >   HTH,
> >   >   M-
> >   >   ----- Original Message -----
> >   >   From: "Gaet" <ga...@free.fr>
> >   >   To: "Struts Users Mailing List" <us...@struts.apache.org>
> >   >   Sent: Wednesday, November 30, 2005 9:29 AM
> >   >   Subject: Re: Parameter of ActionMessage...
> >   >
> >   >
> >   >   > Nobody knows?
> >   >   >
> >   >   > Thanks for your time...
> >   >   >
> >   >   > ----- Original Message -----
> >   >   > From: Gaet
> >   >   > To: Mailing List Struts
> >   >   > Sent: Wednesday, November 30, 2005 12:14 PM
> >   >   > Subject: Parameter of ActionMessage...
> >   >   >
> >   >   >
> >   >   > Hi the list!
> >   >   >
> >   >   > Is it possible to give a key of the ressources.properties in
> parameter of
> >   >   > an
> >   >   > ActionMessage?
> >   >   >
> >   >   > Example :
> >   >   > ----------
> >   >   >
> >   >   > # In Struts Action file
> >   >   >    errors.add(ActionMessages.GLOBAL_MESSAGE, new
> >   >   > ActionMessage("error.field.mandatory","label.name"));
> >   >   >
> >   >   > # In ressources.properties  file
> >   >   >    error.field.mandatory = The field '{0}' is mandatory
> >   >   >    label.name = Your Name
> >   >   >
> >   >   > I want the following result :  "The field 'Your Name' is
> mandatory"
> >   >   >
> >   >   >
> >   >   > Thanks for your help!
> >   >   >
> >   >   >
> >   >   >
> ---------------------------------------------------------------------
> >   >   > 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
> >   >
> >   >
> >
> >
> >   ---------------------------------------------------------------------
> >   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
>
>


--
Yujun Liang
yujun.liang@acm.org

Re: Parameter of ActionMessage...

Posted by Laurie Harper <la...@holoweb.net>.
Gaet wrote:
> Thanks Laurie,
> 
> It's exactly what I want but in fact I want to this in an ActionForm class.
> And from and ActionForm, I can't access to getResources(..) method
 >
 > How to achieve that in an ActionForm? is it possible?

Hmm, in that case you may be out of luck; ActionMessage works by storing 
resource keys which then get resolved (looked up in a resource bundle) 
when the message is rendered. I'm not sure there's a way to get a 
resource bundle from an ActionForm instance -- unless you pass in a 
reference to the appropriate bundle in a setup action and store the form 
bean in session scope so the reference is still valid during subsequent 
requests, when you need to reference it.

> Moreover, why to you define variable "locale" because you don't use it afterwhile...

Oops, I simplified the example code I posted and that was a left-over.

L.

> 
> Thank you very much!
> 
> 
>  
>   ----- Original Message ----- 
>   From: Laurie Harper 
>   To: user@struts.apache.org 
>   Sent: Wednesday, November 30, 2005 11:36 PM
>   Subject: Re: Parameter of ActionMessage...
> 
> 
>   Gaet, ActionMessage doesn't support doing that lookup for you 
>   automatically, but you can achieve what you want fairly easily:
> 
>      Locale locale = request.getLocale();
>      String arg = getResources(request).getMessage("label.name");
>      errors.add(ActionMessages.GLOBAL_MESSAGE,
>        new ActionMessage("error.field.mandatory", arg));
> 
>   L.
> 
>   Gaet wrote:
>   > Thanks Martin,
>   > 
>   > But I want to prepare the error message in the action tag because after, in my JSP, I loop over my errors with <html:messages> tag...
>   > 
>   > I don't know if I'm clear, but if I write the following code :
>   > 
>   > errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.field.mandatory","label.name"));
>   > 
>   > The result will be "The field label.name is mandatory"
>   > 
>   > but I would like 'label.name' replaced by its value defined in the resource properties....in order to have the result "The field Your Name is mandatory"
>   > 
>   > Thanks!
>   >  
>   >   ----- Original Message ----- 
>   >   From: Martin Gainty 
>   >   To: Struts Users Mailing List 
>   >   Sent: Wednesday, November 30, 2005 4:47 PM
>   >   Subject: Re: Parameter of ActionMessage...
>   > 
>   > 
>   >   Bonjour gaet-
>   > 
>   >   the current implementation supports passing in parameters to the 
>   >   bean:message tag at runtime e.g.
>   >   <bean:message key="label.welcome" arg0="Firstname"/>
>   > 
>   >   which will produce
>   >   The field 'Firstname' is mandatory
>   > 
>   >   HTH,
>   >   M-
>   >   ----- Original Message ----- 
>   >   From: "Gaet" <ga...@free.fr>
>   >   To: "Struts Users Mailing List" <us...@struts.apache.org>
>   >   Sent: Wednesday, November 30, 2005 9:29 AM
>   >   Subject: Re: Parameter of ActionMessage...
>   > 
>   > 
>   >   > Nobody knows?
>   >   >
>   >   > Thanks for your time...
>   >   >
>   >   > ----- Original Message ----- 
>   >   > From: Gaet
>   >   > To: Mailing List Struts
>   >   > Sent: Wednesday, November 30, 2005 12:14 PM
>   >   > Subject: Parameter of ActionMessage...
>   >   >
>   >   >
>   >   > Hi the list!
>   >   >
>   >   > Is it possible to give a key of the ressources.properties in parameter of 
>   >   > an
>   >   > ActionMessage?
>   >   >
>   >   > Example :
>   >   > ----------
>   >   >
>   >   > # In Struts Action file
>   >   >    errors.add(ActionMessages.GLOBAL_MESSAGE, new
>   >   > ActionMessage("error.field.mandatory","label.name"));
>   >   >
>   >   > # In ressources.properties  file
>   >   >    error.field.mandatory = The field '{0}' is mandatory
>   >   >    label.name = Your Name
>   >   >
>   >   > I want the following result :  "The field 'Your Name' is mandatory"
>   >   >
>   >   >
>   >   > Thanks for your help!
>   >   >
>   >   >
>   >   > ---------------------------------------------------------------------
>   >   > 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
>   > 
>   > 
> 
> 
>   ---------------------------------------------------------------------
>   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: Parameter of ActionMessage...

Posted by Oles <os...@lohika.odessa.ua>.
*People!
Prompt please Good ** Struts 1.1 tutorials?
And what have changed at 1.1 release?
*

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