remove conversion validation message in struts 2 or make it general

In my struts2 application I have field named carrierNo that accepts integer, when i put string in it gives me this validation error message:

    *Invalid field value for field "carrierNo".*

i can customize this error message in the properties file like this

    invalid.fieldvalue.carrierNo=this field does not accept characters

but i don't want to write a customized message for every non String field in my web application, i want to make it general, i tried the following but it did not work

  invalid.fieldvalue.%{getText(fieldName)}=this field does not accept characters

if there is no way to make general, please help me disable this message at all. then i will use converstion field validator with single message that i define in the properties file.

so my request is to help me make this invalid.fieldvalue.carrierNo general something like this form invalid.fieldvalue.%{getText(fieldName)}

or disable the display of this error message Invalid field value for field "carrierNo".


You could create your own implementation of ConversionErrorInterceptor which finds out the class of failed field and gets your custom message.

Edit: See source code for ConversionErrorInterceptor. For example you could do something like this in your custom interceptor inside intercept method

// get field by name from action
Field f = invocation.getAction().getClass().getDeclaredField(propertyName);
// get type of field
Class clz = f.getType();

String message = LocalizedTextUtil.findDefaultText(XWorkMessages.DEFAULT_INVALID_FIELDVALUE + "." + clz,

And in your file put, xwork.default.invalid.fieldvalue.float, etc.

Need Your Help

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.