You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by cm132005 <cm...@gmail.com> on 2009/05/04 21:27:07 UTC

Struts 2 - Parameterized error messages

Hi,
 
We are migrating our Struts 1.x application to Struts 2.1.6 and currently we
are using Struts Validation framework where the parameterized error messages
are picked up from the resource bundle.

field.required=Field '{0}' is required.
field.numeric=Field '{0}' must be a number.

Expected output:
Field 'First Name' is required.
Field 'Last Name' is required.
Field 'Age' must be a number.
Field 'Cost' must be a number.

The parameter is not always an input value but a label or a String being
passed. It is working fine in Struts 1.x using ActionMessage:

errors.add("fName", new ActionMessage("field.required", "First Name"));

But not working in Struts 2 using getText():
//String getText(String key, List args);
//String getText(String key, String[] args);
addActionError(getText("field.name", new String[] { "First Name"}));

Any help on how to achieve this in Struts 2 would be greatly appreciated.

Thanks.
-- 
View this message in context: http://www.nabble.com/Struts-2---Parameterized-error-messages-tp23374965p23374965.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts 2 - Parameterized error messages

Posted by kamlesh sharma <ka...@gmail.com>.
Thanks you very much it's works for me.


Chris Pratt wrote:
> 
> Try:
> 
> field.amount={0} can not be '$'{1} for Sequence {2}.
> 
> The single quotes tell the underlying MessageFormat that the dollar sign
> should be treated literally.  You might also be able to use
> {1,number,currency} which I think may include the proper currency symbol
> automatically.
>   (*Chris*)
> 
> On Mon, Jan 24, 2011 at 8:42 PM, <jl...@gmail.com> wrote:
> 
>> I thin that the symbol $ is messing the result. Have you tried this?
>> field.amount= {0} can not be {1} for Sequence {2}.
>>
>> addActionError(getText("field.amount", new String[] { "Amount", "$0.00",
>> "987654"}));
>>
>> Jose Luis
>> Sent via BlackBerry from T-Mobile
>>
>> -----Original Message-----
>> From: kamlesh sharma <ka...@gmail.com>
>> Date: Mon, 24 Jan 2011 20:33:20
>> To: <us...@struts.apache.org>
>> Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>> Subject: Re: Struts 2 - Parameterized error messages
>>
>>
>> Hi,
>>   i am facing same problem with other message. i.e
>>
>> field.amount= {0} can not be ${1} for Sequence {2}.
>>
>> On UI interface it is displaying below message:
>>
>> Amount can not be 1 for Sequence 987654.
>>
>> instead of
>>
>> Amount can not be $0.00 for Sequence 987654.
>>
>> Means ${  is not working for any error message.
>>
>> Parameter is passed currectly
>>
>> addActionError(getText("field.amount", new String[] { "Amount", "0.00",
>> "987654"}));
>>
>> Any help would be greatly appreciated
>>
>> Thanks
>> Kamlesh
>>
>>
>>
>>
>> Chris Pratt wrote:
>> >
>> > What do you mean by "not working"?  Are you seeing:
>> >
>> > Field {0} is required.
>> >
>> > on your interface?  If so, I suspect what you need to do is:
>> >
>> > field.required=Field ''{0}'' is required.
>> > field.numeric=Field ''{0}'' must be a number.
>> >
>> > Since the new code runs the messages through MessageFormat, and
>> > MessageFormat considers anything between apostrophe's to be a literal
>> > value,
>> > you have to use double apostrophe's to represent a single apostrophe in
>> > the
>> > output.
>> >   (*Chris*)
>> >
>> > On Mon, May 4, 2009 at 12:27 PM, cm132005 <cm...@gmail.com> wrote:
>> >
>> >>
>> >> Hi,
>> >>
>> >> We are migrating our Struts 1.x application to Struts 2.1.6 and
>> currently
>> >> we
>> >> are using Struts Validation framework where the parameterized error
>> >> messages
>> >> are picked up from the resource bundle.
>> >>
>> >> field.required=Field '{0}' is required.
>> >> field.numeric=Field '{0}' must be a number.
>> >>
>> >> Expected output:
>> >> Field 'First Name' is required.
>> >> Field 'Last Name' is required.
>> >> Field 'Age' must be a number.
>> >> Field 'Cost' must be a number.
>> >>
>> >> The parameter is not always an input value but a label or a String
>> being
>> >> passed. It is working fine in Struts 1.x using ActionMessage:
>> >>
>> >> errors.add("fName", new ActionMessage("field.required", "First
>> Name"));
>> >>
>> >> But not working in Struts 2 using getText():
>> >> //String getText(String key, List args);
>> >> //String getText(String key, String[] args);
>> >> addActionError(getText("field.name", new String[] { "First Name"}));
>> >>
>> >> Any help on how to achieve this in Struts 2 would be greatly
>> appreciated.
>> >>
>> >> Thanks.
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/Struts-2---Parameterized-error-messages-tp23374965p23374965.html
>> >> Sent from the Struts - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> >> For additional commands, e-mail: user-help@struts.apache.org
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Struts-2---Parameterized-error-messages-tp23374965p30748110.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/Struts-2---Parameterized-error-messages-tp23374965p30774297.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts 2 - Parameterized error messages

Posted by Chris Pratt <th...@gmail.com>.
Try:

field.amount={0} can not be '$'{1} for Sequence {2}.

The single quotes tell the underlying MessageFormat that the dollar sign
should be treated literally.  You might also be able to use
{1,number,currency} which I think may include the proper currency symbol
automatically.
  (*Chris*)

On Mon, Jan 24, 2011 at 8:42 PM, <jl...@gmail.com> wrote:

> I thin that the symbol $ is messing the result. Have you tried this?
> field.amount= {0} can not be {1} for Sequence {2}.
>
> addActionError(getText("field.amount", new String[] { "Amount", "$0.00",
> "987654"}));
>
> Jose Luis
> Sent via BlackBerry from T-Mobile
>
> -----Original Message-----
> From: kamlesh sharma <ka...@gmail.com>
> Date: Mon, 24 Jan 2011 20:33:20
> To: <us...@struts.apache.org>
> Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
> Subject: Re: Struts 2 - Parameterized error messages
>
>
> Hi,
>   i am facing same problem with other message. i.e
>
> field.amount= {0} can not be ${1} for Sequence {2}.
>
> On UI interface it is displaying below message:
>
> Amount can not be 1 for Sequence 987654.
>
> instead of
>
> Amount can not be $0.00 for Sequence 987654.
>
> Means ${  is not working for any error message.
>
> Parameter is passed currectly
>
> addActionError(getText("field.amount", new String[] { "Amount", "0.00",
> "987654"}));
>
> Any help would be greatly appreciated
>
> Thanks
> Kamlesh
>
>
>
>
> Chris Pratt wrote:
> >
> > What do you mean by "not working"?  Are you seeing:
> >
> > Field {0} is required.
> >
> > on your interface?  If so, I suspect what you need to do is:
> >
> > field.required=Field ''{0}'' is required.
> > field.numeric=Field ''{0}'' must be a number.
> >
> > Since the new code runs the messages through MessageFormat, and
> > MessageFormat considers anything between apostrophe's to be a literal
> > value,
> > you have to use double apostrophe's to represent a single apostrophe in
> > the
> > output.
> >   (*Chris*)
> >
> > On Mon, May 4, 2009 at 12:27 PM, cm132005 <cm...@gmail.com> wrote:
> >
> >>
> >> Hi,
> >>
> >> We are migrating our Struts 1.x application to Struts 2.1.6 and
> currently
> >> we
> >> are using Struts Validation framework where the parameterized error
> >> messages
> >> are picked up from the resource bundle.
> >>
> >> field.required=Field '{0}' is required.
> >> field.numeric=Field '{0}' must be a number.
> >>
> >> Expected output:
> >> Field 'First Name' is required.
> >> Field 'Last Name' is required.
> >> Field 'Age' must be a number.
> >> Field 'Cost' must be a number.
> >>
> >> The parameter is not always an input value but a label or a String being
> >> passed. It is working fine in Struts 1.x using ActionMessage:
> >>
> >> errors.add("fName", new ActionMessage("field.required", "First Name"));
> >>
> >> But not working in Struts 2 using getText():
> >> //String getText(String key, List args);
> >> //String getText(String key, String[] args);
> >> addActionError(getText("field.name", new String[] { "First Name"}));
> >>
> >> Any help on how to achieve this in Struts 2 would be greatly
> appreciated.
> >>
> >> Thanks.
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Struts-2---Parameterized-error-messages-tp23374965p23374965.html
> >> Sent from the Struts - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Struts-2---Parameterized-error-messages-tp23374965p30748110.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts 2 - Parameterized error messages

Posted by jl...@gmail.com.
I thin that the symbol $ is messing the result. Have you tried this?
field.amount= {0} can not be {1} for Sequence {2}.

addActionError(getText("field.amount", new String[] { "Amount", "$0.00",
"987654"})); 

Jose Luis
Sent via BlackBerry from T-Mobile

-----Original Message-----
From: kamlesh sharma <ka...@gmail.com>
Date: Mon, 24 Jan 2011 20:33:20 
To: <us...@struts.apache.org>
Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
Subject: Re: Struts 2 - Parameterized error messages


Hi,
   i am facing same problem with other message. i.e 

field.amount= {0} can not be ${1} for Sequence {2}.

On UI interface it is displaying below message:

Amount can not be 1 for Sequence 987654.

instead of 

Amount can not be $0.00 for Sequence 987654.

Means ${  is not working for any error message.

Parameter is passed currectly

addActionError(getText("field.amount", new String[] { "Amount", "0.00",
"987654"})); 

Any help would be greatly appreciated

Thanks 
Kamlesh




Chris Pratt wrote:
> 
> What do you mean by "not working"?  Are you seeing:
> 
> Field {0} is required.
> 
> on your interface?  If so, I suspect what you need to do is:
> 
> field.required=Field ''{0}'' is required.
> field.numeric=Field ''{0}'' must be a number.
> 
> Since the new code runs the messages through MessageFormat, and
> MessageFormat considers anything between apostrophe's to be a literal
> value,
> you have to use double apostrophe's to represent a single apostrophe in
> the
> output.
>   (*Chris*)
> 
> On Mon, May 4, 2009 at 12:27 PM, cm132005 <cm...@gmail.com> wrote:
> 
>>
>> Hi,
>>
>> We are migrating our Struts 1.x application to Struts 2.1.6 and currently
>> we
>> are using Struts Validation framework where the parameterized error
>> messages
>> are picked up from the resource bundle.
>>
>> field.required=Field '{0}' is required.
>> field.numeric=Field '{0}' must be a number.
>>
>> Expected output:
>> Field 'First Name' is required.
>> Field 'Last Name' is required.
>> Field 'Age' must be a number.
>> Field 'Cost' must be a number.
>>
>> The parameter is not always an input value but a label or a String being
>> passed. It is working fine in Struts 1.x using ActionMessage:
>>
>> errors.add("fName", new ActionMessage("field.required", "First Name"));
>>
>> But not working in Struts 2 using getText():
>> //String getText(String key, List args);
>> //String getText(String key, String[] args);
>> addActionError(getText("field.name", new String[] { "First Name"}));
>>
>> Any help on how to achieve this in Struts 2 would be greatly appreciated.
>>
>> Thanks.
>> --
>> View this message in context:
>> http://www.nabble.com/Struts-2---Parameterized-error-messages-tp23374965p23374965.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/Struts-2---Parameterized-error-messages-tp23374965p30748110.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts 2 - Parameterized error messages

Posted by kamlesh sharma <ka...@gmail.com>.
Hi,
   i am facing same problem with other message. i.e 

field.amount= {0} can not be ${1} for Sequence {2}.

On UI interface it is displaying below message:

Amount can not be 1 for Sequence 987654.

instead of 

Amount can not be $0.00 for Sequence 987654.

Means ${  is not working for any error message.

Parameter is passed currectly

addActionError(getText("field.amount", new String[] { "Amount", "0.00",
"987654"})); 

Any help would be greatly appreciated

Thanks 
Kamlesh




Chris Pratt wrote:
> 
> What do you mean by "not working"?  Are you seeing:
> 
> Field {0} is required.
> 
> on your interface?  If so, I suspect what you need to do is:
> 
> field.required=Field ''{0}'' is required.
> field.numeric=Field ''{0}'' must be a number.
> 
> Since the new code runs the messages through MessageFormat, and
> MessageFormat considers anything between apostrophe's to be a literal
> value,
> you have to use double apostrophe's to represent a single apostrophe in
> the
> output.
>   (*Chris*)
> 
> On Mon, May 4, 2009 at 12:27 PM, cm132005 <cm...@gmail.com> wrote:
> 
>>
>> Hi,
>>
>> We are migrating our Struts 1.x application to Struts 2.1.6 and currently
>> we
>> are using Struts Validation framework where the parameterized error
>> messages
>> are picked up from the resource bundle.
>>
>> field.required=Field '{0}' is required.
>> field.numeric=Field '{0}' must be a number.
>>
>> Expected output:
>> Field 'First Name' is required.
>> Field 'Last Name' is required.
>> Field 'Age' must be a number.
>> Field 'Cost' must be a number.
>>
>> The parameter is not always an input value but a label or a String being
>> passed. It is working fine in Struts 1.x using ActionMessage:
>>
>> errors.add("fName", new ActionMessage("field.required", "First Name"));
>>
>> But not working in Struts 2 using getText():
>> //String getText(String key, List args);
>> //String getText(String key, String[] args);
>> addActionError(getText("field.name", new String[] { "First Name"}));
>>
>> Any help on how to achieve this in Struts 2 would be greatly appreciated.
>>
>> Thanks.
>> --
>> View this message in context:
>> http://www.nabble.com/Struts-2---Parameterized-error-messages-tp23374965p23374965.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/Struts-2---Parameterized-error-messages-tp23374965p30748110.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts 2 - Parameterized error messages

Posted by cm132005 <cm...@gmail.com>.
Thank you, Chris! It was displaying "Field {0} is required." and it worked
fine with two apostrophes. Appreciate your help.


Chris Pratt wrote:
> 
> What do you mean by "not working"?  Are you seeing:
> 
> Field {0} is required.
> 
> on your interface?  If so, I suspect what you need to do is:
> 
> field.required=Field ''{0}'' is required.
> field.numeric=Field ''{0}'' must be a number.
> 
> Since the new code runs the messages through MessageFormat, and
> MessageFormat considers anything between apostrophe's to be a literal
> value,
> you have to use double apostrophe's to represent a single apostrophe in
> the
> output.
>   (*Chris*)
> 
> On Mon, May 4, 2009 at 12:27 PM, cm132005 <cm...@gmail.com> wrote:
> 
>>
>> Hi,
>>
>> We are migrating our Struts 1.x application to Struts 2.1.6 and currently
>> we
>> are using Struts Validation framework where the parameterized error
>> messages
>> are picked up from the resource bundle.
>>
>> field.required=Field '{0}' is required.
>> field.numeric=Field '{0}' must be a number.
>>
>> Expected output:
>> Field 'First Name' is required.
>> Field 'Last Name' is required.
>> Field 'Age' must be a number.
>> Field 'Cost' must be a number.
>>
>> The parameter is not always an input value but a label or a String being
>> passed. It is working fine in Struts 1.x using ActionMessage:
>>
>> errors.add("fName", new ActionMessage("field.required", "First Name"));
>>
>> But not working in Struts 2 using getText():
>> //String getText(String key, List args);
>> //String getText(String key, String[] args);
>> addActionError(getText("field.name", new String[] { "First Name"}));
>>
>> Any help on how to achieve this in Struts 2 would be greatly appreciated.
>>
>> Thanks.
>> --
>> View this message in context:
>> http://www.nabble.com/Struts-2---Parameterized-error-messages-tp23374965p23374965.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts-2---Parameterized-error-messages-tp23374965p23387752.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts 2 - Parameterized error messages

Posted by Chris Pratt <th...@gmail.com>.
What do you mean by "not working"?  Are you seeing:

Field {0} is required.

on your interface?  If so, I suspect what you need to do is:

field.required=Field ''{0}'' is required.
field.numeric=Field ''{0}'' must be a number.

Since the new code runs the messages through MessageFormat, and
MessageFormat considers anything between apostrophe's to be a literal value,
you have to use double apostrophe's to represent a single apostrophe in the
output.
  (*Chris*)

On Mon, May 4, 2009 at 12:27 PM, cm132005 <cm...@gmail.com> wrote:

>
> Hi,
>
> We are migrating our Struts 1.x application to Struts 2.1.6 and currently
> we
> are using Struts Validation framework where the parameterized error
> messages
> are picked up from the resource bundle.
>
> field.required=Field '{0}' is required.
> field.numeric=Field '{0}' must be a number.
>
> Expected output:
> Field 'First Name' is required.
> Field 'Last Name' is required.
> Field 'Age' must be a number.
> Field 'Cost' must be a number.
>
> The parameter is not always an input value but a label or a String being
> passed. It is working fine in Struts 1.x using ActionMessage:
>
> errors.add("fName", new ActionMessage("field.required", "First Name"));
>
> But not working in Struts 2 using getText():
> //String getText(String key, List args);
> //String getText(String key, String[] args);
> addActionError(getText("field.name", new String[] { "First Name"}));
>
> Any help on how to achieve this in Struts 2 would be greatly appreciated.
>
> Thanks.
> --
> View this message in context:
> http://www.nabble.com/Struts-2---Parameterized-error-messages-tp23374965p23374965.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>