2
votes

I found the documentation for how to create a custom type converter with Spring 3, but I can't find any examples of registering the converter in Grails so that bindData can use it.

I tried adding this configuration to the conf/spring/resources.groovy file:

conversionService(org.springframework.context.support.ConversionServiceFactoryBean) {
    converters {
        com.initech.reports.tps.StringToFooConverter
    }   
}

This ends up stepping on something, because as soon as I add the converter in I get a stacktrace on startup like this:

2012-06-21 10:09:50,614 [main] ERROR context.GrailsContextLoader - Error executing bootstraps: Error creating bean with name 'FooApprovers': Cannot create inner bean '(inner bean)' of type [org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection] while setting bean property 'schemaCollection'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#7': Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String[]' to required type 'org.springframework.core.io.Resource[]' for property 'xsds'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value "{/WEB-INF/ws/FooApproversService.xsd}" from type 'java.lang.String[]' to type 'org.springframework.core.io.Resource[]'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from 'java.lang.String' to 'org.springframework.core.io.Resource' org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'FooApprovers': Cannot create inner bean '(inner bean)' of type [org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection] while setting bean property 'schemaCollection'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#7': Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String[]' to required type 'org.springframework.core.io.Resource[]' for property 'xsds'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value "{/WEB-INF/ws/FooApproversService.xsd}" from type 'java.lang.String[]' to type 'org.springframework.core.io.Resource[]'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from 'java.lang.String' to 'org.springframework.core.io.Resource' at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212) at grails.web.container.EmbeddableServer$start.call(Unknown Source) at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158) at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy) at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280) at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy) at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149) at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy) at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116) at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy) at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59) at RunApp$_run_closure1.doCall(RunApp:33) at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381) at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415) at gant.Gant$_dispatch_closure7.doCall(Gant.groovy) at gant.Gant.withBuildListeners(Gant.groovy:427) at gant.Gant.this$2$withBuildListeners(Gant.groovy) at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source) at gant.Gant.dispatch(Gant.groovy:415) at gant.Gant.this$2$dispatch(Gant.groovy) at gant.Gant.invokeMethod(Gant.groovy) at gant.Gant.executeTargets(Gant.groovy:590) at gant.Gant.executeTargets(Gant.groovy:589)

I'm using Grails 1.3.7 (includes Spring 3.0.5).

So apparently there is some other way type converters have been getting added and I messed that up by configuring the conversion service explicitly? Is there a way to register a custom type converter without stepping on other converters?

1

1 Answers

1
votes

You are looking for custom property editors i guess.

You will need to create your custom property editor, and a property editor registrar and then register your registrar in resources.groovy - After that bindDate should be able to use that

See this article