[英]how to bind multi field date to grails 4 date?
I have a simple Book domain.我有一个简单的书域。
class Book {
String title
Date published
static constraints = {
}
}
I have created a simple form for book creation我为书籍创作创建了一个简单的表格
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<title></title>
</head>
<body>
<g:form action="save">
Title: <g:textField name="title"></g:textField>
<br>
Published:
<input type="text" name="startDateTime_dayMonthYear" id="startDate" value="01/06/2022" maxLength="10" size="8" pattern="^\d{1,2}/\d{1,2}/\d{4}$" placeholder="mm/dd/yyyy" />
<input type="text" name="startDateTime_hourMin" id="startDateTime_hourMin" value="8:00" maxLength="5" size="3.5" pattern="^([1-9]|[1][0-2]):[0-5][0-9]$" autocomplete="off" placeholder="hh:ss" />
<select name="startDateTime_meridian" id="startDateTime_meridian" >
<option value="AM" selected="selected" >AM</option>
<option value="PM" >PM</option>
</select>
<select name="startDateTime_timeZone" id="startDateTime_timeZone" >
<option value="US/Hawaii" >(GMT-10:00) US/Hawaii</option>
<option value="US/Alaska" >(GMT-09:00) US/Alaska</option>
<option value="US/Pacific" >(GMT-08:00) US/Pacific</option>
<option value="US/Arizona" >(GMT-07:00) US/Arizona</option>
<option value="US/Mountain" selected="selected" >(GMT-07:00) US/Mountain</option>
<option value="US/Central" >(GMT-06:00) US/Central</option>
<option value="US/Eastern" >(GMT-05:00) US/Eastern</option>
<option value="US/East-Indiana" >(GMT-05:00) US/East-Indiana</option>
</select>
<br>
<g:submitButton name="Submit"></g:submitButton>
</g:form>
</body>
</html>
create and save actions are as follows创建和保存动作如下
def create(){
}
def save(){
def book = new Book()
bindData(book, params)
book.save()
redirect(actionName: "index")
}
For referance the form looks like this供参考,表格如下所示
Is there a way to bind the published date property with this multi field date structure?有没有办法将发布的日期属性与这个多字段日期结构绑定? I know the way to bind date in grails 4 from single text field but with multi fields like this i cannot find resource on how to do it.我知道在 grails 4 中从单个文本字段绑定日期的方法,但是对于像这样的多个字段,我找不到有关如何执行此操作的资源。
I am using grails 4.0.10.我正在使用 grails 4.0.10。 I appreciate any help.我很感激任何帮助。 Thanks!谢谢!
Is there a way to bind the published date property with this multi field date structure?有没有办法将发布的日期属性与这个多字段日期结构绑定?
If you mean by way of using the data binder built into Grails, I think the answer is no.如果您的意思是使用 Grails 中内置的数据绑定器,我认为答案是否定的。 I don't think our binder has support for pulling in the timezone.我认为我们的活页夹不支持拉入时区。 The StructuredEditor
at https://github.com/grails/grails-core/blob/bc9dd3402ac6a78b0b30d4b9333cbc55ff50029d/grails-web-common/src/main/groovy/org/grails/web/binding/StructuredDateEditor.java knows about year, month, day, hour and minute. The StructuredEditor
at https://github.com/grails/grails-core/blob/bc9dd3402ac6a78b0b30d4b9333cbc55ff50029d/grails-web-common/src/main/groovy/org/grails/web/binding/StructuredDateEditor.java knows about year, month,日、小时和分钟。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.