Hi all,
I am trying to bind an Edit control with the Calendar object. I referred to the link below and decided to use custom binding.
However the link explains how to bind with Date class as there's a ready CustomDateEditor class available.
I implemented a CalendarEditor class of my own:
class CalendarEditor extends CustomDateEditor {
public CalendarEditor(DateFormat format, boolean canBeEmpty) {
super(format, canBeEmpty)
}
public void setAsText(String text) {
super.setAsText(text)
def value = this.value
if (value instanceof Date) {
Calendar cal = Calendar.instance
cal.time = value this.value = cal
}
}
public String getAsText() {
def value = this.value
if (value instanceof Calendar) {
this.value = value.time
}
return super.getAsText()
}
}
Then as the above posts mention, implemented CustomPropertyEditorRegistrar
public class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(Calendar.class, new CalendarEditor(new SimpleDateFormat("MM/dd/yyyy"), true));
}
}
Also declared both CustomPropertyEditorRegistrar and CustomDateEditor in grails-app/conf/spring/resources.groovy file.
I though still get an error saying, "Failed to convert property value of type [java.lang.String] to required type [java.util.Calendar] for property dateOfBirth"
Any help is appreciated.
Thanks.