Grails JIRA

  • Log In Access more options
    • Online Help
    • GreenHopper Help
    • Agile Answers
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Agile
Grails
  • Grails
  • GRAILS-3413 Top level task: Data binding improvem...
  • GRAILS-1793

Empty date field cannot be persisted using view

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.0-RC1
  • Fix Version/s: 1.1-beta3
  • Component/s: Persistence, TagLib
  • Labels:
    None

Description

As described on http://www.nabble.com/Date-not-valid%3A-date-can-be-null--tf4759422.html empty date fields cannot be persisted, resulting in an invalid date error message.

Using noSelection attribute as in

<g:datePicker name="myDate" value="$

{new Date()}

" noSelection="['':'-Choose-']"/>

does not work.

Issue Links

is duplicated by

Bug - A problem which impairs or prevents the functions of the product. GRAILS-1530 datePicker noSelection does not work when editing a already persisted date

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.

Bug - A problem which impairs or prevents the functions of the product. GRAILS-2556 Property offeringDate must be a valid Date even if that field allows null

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.

Bug - A problem which impairs or prevents the functions of the product. GRAILS-3981 CLONE -Property offeringDate must be a valid Date even if that field allows null

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.
relates to

Bug - A problem which impairs or prevents the functions of the product. GRAILS-4922 Empty date gives typeMismatch.java.util.Date

  • Critical - Crashes, loss of data, severe memory leak.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
  • Git Commits
Hide
Permalink
Marc Guillemot added a comment - 10/Mar/08 8:03 AM

A workaround is:

1) use g:datePicker undocumented default="..." attribute in the view

<g:datePicker name="myDate" value="$

{new Date()}

" noSelection="['':'-Choose-']" default="none"/>

2) remove the field from the map used for binding if some/all fields is/are empty

def excludes = []
if (!params.myDate_day)
excludes << "myDate"
bindData(myDomainObject, params, excludes)

(note that this has to be done in both save and update and that bindData has to be used rather than properties assignment)

Show
Marc Guillemot added a comment - 10/Mar/08 8:03 AM A workaround is: 1) use g:datePicker undocumented default="..." attribute in the view <g:datePicker name="myDate" value="$ {new Date()} " noSelection=" ['':'-Choose-'] " default="none"/> 2) remove the field from the map used for binding if some/all fields is/are empty def excludes = [] if (!params.myDate_day) excludes << "myDate" bindData(myDomainObject, params, excludes) (note that this has to be done in both save and update and that bindData has to be used rather than properties assignment)
Hide
Permalink
dion gillard added a comment - 03/Apr/08 12:15 AM

I'm on Grails 1.0.1 and workaround 1) doesn't work for me.

I have:

<g:datePicker precision="day" name="publicLiabilityExpiry" value="$

{contractor?.publicLiabilityExpiry}

" default="none" noSelection="$

{['':'--']}

"/>

and need to use Option 2 to get it to work.

Show
dion gillard added a comment - 03/Apr/08 12:15 AM I'm on Grails 1.0.1 and workaround 1) doesn't work for me. I have: <g:datePicker precision="day" name="publicLiabilityExpiry" value="$ {contractor?.publicLiabilityExpiry} " default="none" noSelection="$ {['':'--']} "/> and need to use Option 2 to get it to work.
Hide
Permalink
Marc Guillemot added a comment - 03/Apr/08 2:20 AM

Seems that I wasn't precise enough: (1) and (2) are not different alternatives but the 2 steps of the workaround

Show
Marc Guillemot added a comment - 03/Apr/08 2:20 AM Seems that I wasn't precise enough: (1) and (2) are not different alternatives but the 2 steps of the workaround
Hide
Permalink
Dennis Carroll added a comment - 08/Jan/09 4:24 PM

I had to use the aforementioned workaround for the save operation:

def hmaCellInstance = new HmaCell()
def excludes = []
if ((!params.demolishedDate_month) ||(!params.demolishedDate_day)||(!params.demolishedDate_year))
excludes << "demolishedDate"
bindData(hmaCellInstance, params, excludes)
// def hmaCellInstance = new HmaCell(params)
...

but was able to make a more generic one for the update operation:

def update = {
def hmaCellInstance = HmaCell.get( params.id )

if(hmaCellInstance) {
// Workaround for http://jira.codehaus.org/browse/GRAILS-1793
def dateError = paramsDateCheck(params)
hmaCellInstance.properties = params
if(!hmaCellInstance.hasErrors() && hmaCellInstance.save()) {
def msg = "Cell $

{params.id}

updated$

{dateError}

."
...

where
def paramsDateCheck ( params ) {
def rc
def names = []
params.each

{ if (it.value == "struct") names.add(it.key) }

names.each {
def aDateString = ""
def allBlank = (params[it+"_day"] == '' & params[it+"_month"] == '' & params[it+"_year"] == '')
def someBlank = (params[it+"_day"] == '' | params[it+"_month"] == '' | params[it+"_year"] == '')
if (allBlank)
params[it] = null
if (someBlank & !allBlank){
params[it] = null
def day = params[it+"_day"] == ''?'dd':params[it+"_day"]
def mon = params[it+"_month"] == ''?'mm':params[it+"_month"]
def year = params[it+"_year"] == ''?'yyyy':params[it+"_year"]
aDateString = "$

{day}

/$

{mon}

/$

{year}

"
rc = ", $

{it}

, $

{aDateString}

, ignored"
}
}
return rc?rc:""
}

Show
Dennis Carroll added a comment - 08/Jan/09 4:24 PM I had to use the aforementioned workaround for the save operation: def hmaCellInstance = new HmaCell() def excludes = [] if ((!params.demolishedDate_month) ||(!params.demolishedDate_day)||(!params.demolishedDate_year)) excludes << "demolishedDate" bindData(hmaCellInstance, params, excludes) // def hmaCellInstance = new HmaCell(params) ... but was able to make a more generic one for the update operation: def update = { def hmaCellInstance = HmaCell.get( params.id ) if(hmaCellInstance) { // Workaround for http://jira.codehaus.org/browse/GRAILS-1793 def dateError = paramsDateCheck(params) hmaCellInstance.properties = params if(!hmaCellInstance.hasErrors() && hmaCellInstance.save()) { def msg = "Cell $ {params.id} updated$ {dateError} ." ... where def paramsDateCheck ( params ) { def rc def names = [] params.each { if (it.value == "struct") names.add(it.key) } names.each { def aDateString = "" def allBlank = (params [it+"_day"] == '' & params [it+"_month"] == '' & params [it+"_year"] == '') def someBlank = (params [it+"_day"] == '' | params [it+"_month"] == '' | params [it+"_year"] == '') if (allBlank) params [it] = null if (someBlank & !allBlank){ params [it] = null def day = params [it+"_day"] == ''?'dd':params [it+"_day"] def mon = params [it+"_month"] == ''?'mm':params [it+"_month"] def year = params [it+"_year"] == ''?'yyyy':params [it+"_year"] aDateString = "$ {day} /$ {mon} /$ {year} " rc = ", $ {it} , $ {aDateString} , ignored" } } return rc?rc:"" }
Hide
Permalink
michael added a comment - 11/Aug/09 2:32 AM

this bug is present in my grails version ( 1.1.1 )
Workaround is ok but this bug will be corrected in futur release ? I must create a new bug report ?

Show
michael added a comment - 11/Aug/09 2:32 AM this bug is present in my grails version ( 1.1.1 ) Workaround is ok but this bug will be corrected in futur release ? I must create a new bug report ?
Hide
Permalink
Marcel Overdijk added a comment - 11/Aug/09 2:39 AM

@micheal: seems like a regression. I would indeed reopen or create a new issue (make sure to set affects version correctly).
Note that in Grails 1.2 M1 there is also a problem with empty dates (GRAILS-4922).

Show
Marcel Overdijk added a comment - 11/Aug/09 2:39 AM @micheal: seems like a regression. I would indeed reopen or create a new issue (make sure to set affects version correctly). Note that in Grails 1.2 M1 there is also a problem with empty dates ( GRAILS-4922 ).
Hide
Permalink
Dennis Carroll added a comment - 01/Dec/09 7:26 PM

This remains a bug in 1.2M3 and if I had a clue where to fix it I would.
Thanks for playing.

Show
Dennis Carroll added a comment - 01/Dec/09 7:26 PM This remains a bug in 1.2M3 and if I had a clue where to fix it I would. Thanks for playing.
Hide
Permalink
Graeme Rocher added a comment - 18/May/11 8:45 AM

Bulk closing bunch of resolved issues

Show
Graeme Rocher added a comment - 18/May/11 8:45 AM Bulk closing bunch of resolved issues

People

  • Assignee:
    Graeme Rocher
    Reporter:
    Marcel Overdijk
Vote (12)
Watch (16)

Dates

  • Created:
    06/Nov/07 12:13 PM
    Updated:
    18/May/11 8:45 AM
    Resolved:
    26/Jan/09 11:29 AM

Agile

  • View on Board
  • Atlassian JIRA (v5.2.1#813-sha1:277a546)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Grails project. Try JIRA - bug tracking software for your team.