首页 > 解决方案 > Grails脚手架,还是不能处理编辑表单中的java8 localdateTime,也不能做Map属性

问题描述

我正在使用 Grails v3.3.9、最新的 grails hibernate 8 和 build.gradle 中的 grails 插件,以及 java8 插件、字段插件(没有任何区别)和 Hibernate 8。

compile "org.hibernate:hibernate-core:5.1.5.Final"
compile group: 'org.hibernate', name: 'hibernate-java8', version: '5.1.5.Final'
compile "org.grails.plugins:gsp"
compile 'org.grails.plugins:grails-java8:1.2.3'  //java 8 features including datetime in GSP
compile 'org.grails.plugins:fields:2.2.10'

我已经在我的域模型上尝试过这个,它扩展了一个带有 LocalDateTime 的抽象类

abstract class Agreement {

    String contractReference
    String status
    LocalDateTime contractSignedDate
    LocalDateTime lastUpdated   //updated by framework
    LocalDateTime dateCreated   //updated by framework

    static constraints = {
        contractReference nullable:false
        status nullable:false
        contractSignedDate nullable:true
    }
}

和具体的类在这里

class MaintenanceAgreement extends Agreement {

    String level
    Map category = [:]  //p1 to p5 and sla details 

    //static belongsTo = [serviceProvider : OrgRoleInstance, maintainer: OrgRoleInstance]

    // implemented as unidirectional many to one !  mag point to org
    static belongsTo = [maintainer: OrgRoleInstance]

    static constraints = {
        level nullable:false
        //serviceProvider nullable:true
        maintainer nullable:false   //ref to maintainer party

        category nullable:false
    }
}

如果我在带有空列的引导程序中的 Db 中有一条记录 - grails 只是没有任何字段持有者用于空条目。返回引导程序并手动创建一个值,重新启动。

至少这次列表和显示渲染在表单上放置了一个实际的

在此处输入图像描述

但是,当您创建一个新表单(或编辑操作)时,您会得到这个。contractSigned (localDateTime)没有 editor,最后域模型有一个属性类别为 Map ,并且Map 列没有编辑器。

在此处输入图像描述

这是一个真正的问题。我可以恢复尝试使用 Date 但这确实是一个倒退,并且该平台建议支持新的数据时间格式。地图列考虑我的后备可能。

我是否在这里遗漏了一些使这项工作有效的东西?还是我有重新提出缺陷?

我在以前的 3.3.8 版本中遇到了这个问题,也没有解决数据时间问题

之前的纪录

另请参阅之前在此处询问功能

在grails中使java新日期成为一等公民

标签: grailsscaffoldinglocaldate

解决方案


不要LocalDateTime在你的类中使用数据类型。您可能无法对其进行编辑。改用Date类型。然后 grails 本身也会为您提供日期选择器来添加和编辑。如果您需要在 GSP 中提取当前日期时间,您可以将${new Date()其用作该字段的值。


推荐阅读