1

Well, here is the code I've tried so far.

public class CustomDateEditorRegistrar implements PropertyEditorRegistrar {

    public void registerCustomEditors(PropertyEditorRegistry registry) {
        registry.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("MM/dd/yyyy hh:mm a"), true))
        registry.registerCustomEditor(Date.class, new StructuredDateEditor(new SimpleDateFormat("MM/dd/yyyy"), true))
    }

}

I am using a calendar jQuery plugin and a regular grails DatePicker, if I just use the first one, I always get an error with the regular grails Date Picker. If I use both, I don't get an error anymore.. However, the calendar saves just the date and not the time? Anyway to fix this? :(

ParkDongJu
  • 13
  • 2

2 Answers2

1

You may want to take a look at this:

Grails Date unmarshalling

and this

Binding a Grails date from params in a controller

Community
  • 1
  • 1
chrislovecnm
  • 2,549
  • 3
  • 20
  • 36
0

I don't think you can register multiple editors for the same type, so I would instead write my own MultiDateEditor subclass of CustomDateEditor (or implement PropertyEditorSupport directly) which tries to bind a date using multiple formats. Then you only need to register MultiDateEditor:

public class CustomDateEditorRegistrar implements PropertyEditorRegistrar {

    public void registerCustomEditors(PropertyEditorRegistry registry) {
        registry.registerCustomEditor(Date.class, new MultiDateEditor(
                ["MM/dd/yyyy hh:mm a", "MM/dd/yyyy"]))
    }    
} 
Dónal
  • 185,044
  • 174
  • 569
  • 824