Grails Date Property Editor

前端 未结 3 1518
心在旅途
心在旅途 2021-02-11 07:48

i\'m using the jQuery UI datepicker instead of the , which is changing the selected date in a textbox. Now I want to save this neatly back into

3条回答
  •  耶瑟儿~
    2021-02-11 08:39

    There shouldn't be that much magic.

    resources.groovy

    beans = {
        customPropertyEditorRegistrar(CustomPropertyEditorRegistrar)
    }
    

    src/groovy/{yourpackage}/CustomPropertyEditorRegistrar.groovy

    class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
        @Override
        void registerCustomEditors(PropertyEditorRegistry registry) {
            // Always set the nullable to true and handle not nullable fields through constraints
            registry.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("dd.MM.yyyy"), true));
        }
    }
    

提交回复
热议问题