In my Grails 2.3.7 app, I have the following command object
class UpdateThresholdsCommand {
Double threshold_1
Double threshold_2
}
The parameters I'm trying to bind to these properties are formatted currency values, e.g. threshold_1=$2,459.04&threshold_2=$1,459.04
I've defined the following implementation of ValueConverter to perform this binding
class CurrencyStringToDoubleConverter implements ValueConverter {
FormatService formatService
@Override
boolean canConvert(Object value) {
value instanceof String
}
@Override
Object convert(Object value) {
formatService.parseCurrency((String) value)
}
@Override
Class<?> getTargetType() {
Double
}
}
and registered it in resources.groovy
currencyStringToDoubleConverter(CurrencyStringToDoubleConverter) {
formatService = ref('formatService')
}
But when a request with params such as those shown above is sent to the action, CurrencyStringToDoubleConverter is never invoked, so the threshold_1 and threshold_2 properties of the command object are null. Why isn't CurrencyStringToDoubleConverter being invoked?
grails.databinding.useSpringBindertotruehave you? The Spring binder does not useValueConverterbeans. - Jeff Scott Brown