Title: Message
I've overhauled how type conversion errors are handled. Type conversion errors are now added to a Map stored in the ActionContext which is available via ActionContext.getContext().getConversionErrors(). This map is a map of field name to values which will allow you to access the original value which failed conversion.
 
I've also implemented 2 ways of populating field errors with the type conversion errors into the field errors of the Action. The first will populate all of the field errors from the conversion errors and is implemented as an Interceptor. There are actually 2 Interceptors, one in XWork and one in WebWork which extends the one in XWork. They differ in the implementation of the method
 
protected boolean shouldAddError(String propertyName, Object value)
 
The XWork version always returns true, whereas the WebWork Interceptor returns false for values of null, "", and {""}, preventing type conversion exceptions for these common empty values from propogating to the field errors of the Action. The WebWork version of this Interceptor has been added to the webwork-defaults.xml and to the defaultStack defined therein.
 
If you choose not to use this Interceptor, you can choose to enable this on a per-field basis by using the Validation framework with the new field validator I've added, defined in the validators.xml file like this:
 
    <validator name="conversion" class="com.opensymphony.xwork.validator.validators.ConversionErrorFieldValidator"/>
This validator will look up the conversion errors and, if it finds a conversion error for the field it is applied to, it will add the appropriate error message to the Action.
 
Both of these methods use the XWorkConverter.getConversionErrorMessage(propertyName, stack) which looks up the type conversion error message for the property name as was done previously, by looking for a message keyed by "invalid.fieldvalue.propertyName" and using a default value if it is not found.
 
Let me know if you find any problems,
 
Jason

Reply via email to