grails - 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 版本中遇到了这个问题,也没有解决数据时间问题
另请参阅之前在此处询问功能
解决方案
不要LocalDateTime
在你的类中使用数据类型。您可能无法对其进行编辑。改用Date
类型。然后 grails 本身也会为您提供日期选择器来添加和编辑。如果您需要在 GSP 中提取当前日期时间,您可以将${new Date()
其用作该字段的值。
推荐阅读
- c++ - constexpr 模板函数的无限递归
- bash - 使用 bash 邮件发送文本,哪个电子邮件客户端会看到并显示为文本?
- typescript - 在 typescript 和 sequelize 中使用泛型强制类型
- javascript - 如何滚动到带有钩子/函数的元素?
- python - 基于时间的最快移动平均值
- java - 如何确保目录中的图像在更改后刷新?
- bash - 我可以在 for 循环中对参数变量使用数学吗?
- ios - Swift 4 - 在其 UIViewController 中更新 UIPageViewController 中的变量
- c++ - 在多线程环境中交换 C++ 映射对象
- javascript - 返回数组中偶数的总和