Hi,
I am trying to apply a Spring 3 custom Formatter in SWF 2.1.1:
It is used through a custom annotation:Code:class AccountNumberFormatter implements Formatter<String> { MaskFormatter mask; public AccountNumberFormatter(String pattern) { try{ mask = new MaskFormatter(pattern); mask.setValueContainsLiteralCharacters(false); }catch(ParseException e) { // TODO e.printStackTrace(); } } public String print(String object, Locale locale) { try{ return mask.valueToString(object); }catch(ParseException e){ return null; } } public String parse(String text, Locale locale) throws ParseException { return (String)mask.stringToValue(text); } }
While other formatters work fine, this one does not. However in plain Spring 3 MVC, it works as expected.Code:@AccountNumberFormat private String accountNumber;
When I have a look at SFW code, I see the following in class BindingModel:
If I override the class and remove the test on the String class, everything works fine.Code:private Object getFormattedValue(String field) { Expression fieldExpression = parseFieldExpression(field, true); Class valueType = fieldExpression.getValueType(boundObject); if (isCustomConverterConfigured(field) || avoidConversion(valueType)) { fieldExpression = parseFieldExpression(fieldExpression.getExpressionString(), false); } Object value = fieldExpression.getValue(boundObject); if ((value instanceof String) == false) { if (avoidConversion(valueType) == false) { PropertyEditor editor = findSpringConvertingPropertyEditor(field, valueType); if (editor != null) { editor.setValue(value); value = editor.getAsText(); } } } return value; }
So what is the reason behind this test ?
I had a look at the previous post but it did not help...


Reply With Quote
