Last updated by 5 years ago

Page: Data Binding and PropertyEditors, Version:0

Grails binding mechanism already has a conversion implementation for the datePicker tag lib. It receives all the fields from datePicker and knows how to convert that to a Date object and bind it to the proper attribute of the target object. But this is the only possible conversion (as far as I know) in Grails so far that is automatically used by the binding mechanism.

GSPs and JSPs are mainly geared towards generating the visual representation, but not really providing any support for the input conversion.

What we look for is a clean way of implementing the input as well as the output "conversions".

in a SpringMVC  application we use PropertyEditorSupport subclasses to register these converters you are talking about. In Controllers that subclass SimpleFormController we can override initBinder() and do something like: 

binder.registerCustomEditor(Date.class, null, new CustomDateEditor(dateFormat, true));


Could not Grails have something like this? We could have custom property editors that would handle these conversions for input (and possibly output). It does not matter if the input comes from more than one field, or one field. As an example: Time estimate input field in a format like "4d 12h 30m", representing 4 days, 12 hours and 30 minutes (like JIRA has). The converter would know how to get this input and convert into a Long representing senconds (or milliseconds, whatever). But how to register this converter? Where would converters be?

maybe we could do something like:

bindData(target, params, ['estimate':MyTimeConverter, 'otherField':OtherConverter])
----Comment from Daiji Takamori: I've come up with a modification of how Scaffolding works that might provide the equivalent functionality to what is requested in this proposal but without requiring significantly new APIs.  See http://jira.codehaus.org/browse/GRAILS-756 (in particular the attachment, which I developed using version 0.4.1).

---- Comment from Luis Fernando Planella Gonzalez: Released a plugin to accomplish this:Extended Data Binding Plugin