Details
-
Type:
Test
-
Status:
Closed
-
Priority:
Major
-
Resolution: Not A Bug
-
Affects Version/s: 2.0.3
-
Fix Version/s: None
-
Component/s: Data binding
-
Labels:None
-
Environment:JDK 1.6
Description
I have 3 domain classes:
package com.example class Parent { String name Date birthDate Long age static constraints = { birthDate(nullable: true) } static mapping = { tablePerHierarchy false } }
package com.example class Child extends Parent{ static constraints = { } }
package example.com class Single { String code Date last static constraints = { last(nullable: true) } }
And 2 controllers:
package com.example class ChildController { static scaffold = true }
package com.example class SingleController { static scaffold = true }
Then I installed templates and updated "renderEditor.template" for use jquery-ui datepicker:
private renderDateEditor(domainClass, property) { def precision = (property.type == Date || property.type == java.sql.Date || property.type == Calendar) ? "day" : "minute"; if (!cp) { return "<g:datePicker name=\"${property.name}\" precision=\"${precision}\" value=\"\${${domainInstance}?.${property.name}}\" />" } else { if (!cp.editable) { return "\${${domainInstance}?.${property.name}?.toString()}" } else { def out = new StringBuffer("") out << "<r:require module=\"jquery-ui-ru\"/>" out << "<input type=\"text\" name=\"${property.name}_datepicker\" id=\"${property.name}_datepicker\" value=\"<g:formatDate date=\"\${${domainInstance}?.${property.name}}\" formatName=\"dateonly.date.format\" />\"/>" out << "<input type=\"hidden\" name=\"${property.name}_day\" id=\"${property.name}_day\" value=\"<g:formatDate date=\"\${${domainInstance}?.${property.name}}\" format=\"dd\" />\"/>" out << "<input type=\"hidden\" name=\"${property.name}_month\" id=\"${property.name}_month\" value=\"<g:formatDate date=\"\${${domainInstance}?.${property.name}}\" format=\"MM\" />\"/>" out << "<input type=\"hidden\" name=\"${property.name}_year\" id=\"${property.name}_year\" value=\"<g:formatDate date=\"\${${domainInstance}?.${property.name}}\" format=\"yyyy\" />\"/>" out << """<g:javascript> \$(document).ready(function () { \$("#${property.name}_datepicker").datepicker({ dateFormat:'dd/mm/yy', onClose: function(dateText, inst) { var date = new Date(dateText.replace(/(\\d+).(\\d+).(\\d+)/, '\$3/\$2/\$1')); if (!isNaN(date)) { \$("#${property.name}_month").val(date.getMonth()+1); \$("#${property.name}_day").val(date.getDate()); \$("#${property.name}_year").val(date.getFullYear()); } }, showAnim: "slide", showOptions: {direction: 'up'}, showOn: "both", autoSize: true, constrainInput: true, showButtonPanel: true }); }) </g:javascript>""" return out.toString() } } }
To BuildConfig.groovy I added:
plugins {
...
compile ":jquery-ui:1.8.15"
...
}
And to applicationResources.groovy:
'jquery-ui-ru' {
dependsOn 'jquery', 'jquery-ui'
resource id: 'js', url: [plugin: "jquery-ui", dir: "js/jquery/i18n", file: "jquery.ui.datepicker-ru.js"], disposition: 'head'
}
Then I ran application. Fill any date in SingleController and ChildController, and save.
In SingleController is all ok, but in ChildController created record with null date (birthDate property).
I added filter to log parameters from requests, and there is all needed data for binding date property in both cases (I mean params like <propertyname>_year, ..._month, ..._day):
... example.MyFilters request params: [action:create, controller:child] example.MyFilters request params: [birthDate_day:1, birthDate_month:5, birthDate_datepicker:01/05/2012, name:dd, age:33, birthDate_year:2012, create:Create, action:save, controller:child] ... example.MyFilters request params: [action:create, controller:single] example.MyFilters request params: [last_year:2012, last_day:1, last_datepicker:01/05/2012, last_month:5, code:er, create:Create, action:save, controller:single] ...
So, inherited domain class have some problems with binding date property from parts: year, month, and day.
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
Sorry, I am mistaken.
I missed magic "date.struct" value.
renderEditor.template must be:
... out << "<input type=\"text\" name=\"${property.name}_datepicker\" id=\"${property.name}_datepicker\" value=\"<g:formatDate date=\"\${${domainInstance}?.${property.name}}\" formatName=\"dateonly.date.format\" />\"/>" out << "<input type=\"hidden\" name=\"${property.name}\" value=\"date.struct\" />" out << "<input type=\"hidden\" name=\"${property.name}_day\" id=\"${property.name}_day\" value=\"<g:formatDate date=\"\${${domainInstance}?.${property.name}}\" format=\"dd\" />\"/>" out << "<input type=\"hidden\" name=\"${property.name}_month\" id=\"${property.name}_month\" value=\"<g:formatDate date=\"\${${domainInstance}?.${property.name}}\" format=\"MM\" />\"/>" out << "<input type=\"hidden\" name=\"${property.name}_year\" id=\"${property.name}_year\" value=\"<g:formatDate date=\"\${${domainInstance}?.${property.name}}\" format=\"yyyy\" />\"/>" ...All works fine.
Please close the issue.