开发者

Grails Scaffolding Default Date

I'm using Grails scaffolding and would like to make a change in the default date during a create. Currently dates default to today's date. How would one开发者_StackOverflow中文版 default it to blank or no date?

Thanks,

Steve


You can do grails install-templates and customize template, used for rendering.

In $PROJECT/src/templates/scaffolding/renderEditor.template there is method renderDateEditor which should be customized to your needs.

This customization will be applied to all new scaffolding operations.


Whatever the default value in your domain object is will show up in the form on create.

class Test {
    Date aDate
}

In that example the domain object has a non-nullable date, so the default value is a newly constructed date. If the domain object gets changed to:

class Test {
    Date aDate
    static constraints = {
        aDate(nullable:true)
    }
}

Then the default value for the date will be null and that's what will show up in the scaffolded create form.

If you want to set the default value explictly, just assign it with a domain object initializer:

class Test {
    Date aDate = Date.parse("yyyy-MM-dd", "2010-01-01")
    static constraints = {
        aDate(nullable:true)
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜