[Grails 2.3.11] GrailsDataBinder issue in src/groovy

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Grails 2.3.11] GrailsDataBinder issue in src/groovy

parthbhagat
This post was updated on .
I am working with Grails 2.1.3. Recently upgraded to Grails 2.3.11.

I am trying to bind date field. Earlier with 2.1.3 it was able to bind date by parsing it automatically based on date format specified. But after upgrading to 2.3.11 it is not binding that date value.

I have a class which is subclassed with specific properties. Both classes are in src/groovy. Child class is marked as @Validateable and here constraints are specified. Now, date field is specified in parent class, which is not marked with any annotation.

Child class is been initialized using new operator.

Here is the code snippet which binds data to child class. This code snippet is from Service class.

GrailsDataBinder binder = GrailsDataBinder.createBinder(childClassCmd, childClassCmd.class.name);
binder.bind(params);

To bind data field I have marked date field as @BindUsing. It works at other places where the class is bound directly in Controller, but not working here. It is giving null on accessing the property.

I am not sure but I think the value is not binding because of its type i.e. java.util.Date. Because String objects are bound properly. Will ValueConverter works fine to solve this? If so, can I have a good link to implement ValueConverter for date field?

Any idea why it is not binding value to the class?

Note: I can not go for @BindingFormat, because the date-time format is locale based and not been read from properties file. It is depends on request from client. So, it will be always locale of client system.
Reply | Threaded
Open this post in threaded view
|

Re: [Grails 2.3.11] GrailsDataBinder issue in src/groovy

parthbhagat
Solved it.

Changed the code which binds data to childClassCmd.

Here is the updated code snippet.
GrailsWebDataBinder webDataBinder = new GrailsWebDataBinder(grailsApplication)
webDataBinder.bind(childClassCmd, params as SimpleMapDataBindingSource)
Not used ValueConverter. Used @BindUsing annotation to bind date value. Only change is the Databinding class used to perform binding.

Hope this will helpful.

Thank you.