struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cm132005 <cm132...@gmail.com>
Subject Re: Struts 2 - Parameterized error messages
Date Tue, 05 May 2009 14:05:03 GMT

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 <cm132005@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


Mime
View raw message