atom feed2 messages in org.codehaus.grails.dev[grails-dev] changed properties in on...
FromSent OnAttachments
calibanDec 30, 2007 5:18 pm 
calibanDec 31, 2007 12:10 am 
Subject:[grails-dev] changed properties in onLoad closure are not persistent
From:caliban (al@hrz.tu-chemnitz.de)
Date:Dec 30, 2007 5:18:50 pm
List:org.codehaus.grails.dev

I would like to store the date of last access to some table entries.

I tried to use the onLoad event to update a lastAccess property. This seemed to work for the view, the lastAccess value was updated. But the changes were never written in the DB.

Every time I accessed the list view, the old value was reloaded from the DB. Can I change properties in the onLoad closure?

I used following domain class:

class Foo {

String name

Date dateCreated; Date lastUpdated; Date lastAccess;

static constraints = { name( nullable:false, unique:true ); lastUpdated(); lastAccess( nullable:true ); }

def beforeInsert = { lastAccess = new Date(); }

def onLoad = { println 'this: ' + this;

def aktDate = new Date(); println 'current time: ' + aktDate; println 'last access time: ' + lastAccess + ' always nearly dateCreated: ' + dateCreated; println 'last upadte: ' + lastUpdated + ' remains unaltered too'; lastAccess = aktDate; println 'new last access: ' + lastAccess; } }

which gave me for the first access by the list view:

this: Foo : 1 current time: Mon Dec 31 02:01:48 CET 2007 last access time: 2007-12-31 02:01:44.878 always nearly dateCreated: 2007-12-31 02:01:44.898 last upadte: 2007-12-31 02:01:44.898 remains unaltered too new last access: Mon Dec 31 02:01:48 CET 2007 2007-12-31 02:01:51.129:/test:INFO: GSP servlet initialized

and for the second access:

this: Foo : 1 current time: Mon Dec 31 02:06:25 CET 2007 last access time: 2007-12-31 02:01:44.878 always nearly dateCreated: 2007-12-31 02:01:44.898 last upadte: 2007-12-31 02:01:44.898 remains unaltered too new last access: Mon Dec 31 02:06:25 CET 2007

and so on:

this: Foo : 1 current time: Mon Dec 31 02:12:37 CET 2007 last access time: 2007-12-31 02:01:44.878 always nearly dateCreated: 2007-12-31 02:01:44.898 last upadte: 2007-12-31 02:01:44.898 remains unaltered too new last access: Mon Dec 31 02:12:37 CET 2007

By the way, there was a similar issue posted some time ago: http://www.nabble.com/Domain-onLoad-event-doesn%27t-appear-to-work-to13714486.html#a13714486 http://www.nabble.com/Domain-onLoad-event-doesn%27t-appear-to-work-to13714486.html#a13714486

Cheers -- View this message in context:
http://www.nabble.com/changed-properties-in-onLoad-closure-are-not-persistent-tp14553204p14553204.html Sent from the grails - dev mailing list archive at Nabble.com.