There are a number of callback methods that Naked
Objects will call on your domain object if present. One of
these is created()
, called after a transient
instance is just instantiated. It's a good place to perform
initialization logic (that would otherwise probably have lived in a
constructor). For example:
class Claim extends AbstractDomainObject { ... void created() { status = "New" date = new Date() } ... }
Note that the method must return void
(Groovy's
def
returns a java.lang.Object
,
which is not what Naked Objects is looking
for).
Other callback methods include:
loading()
and
loaded()
persisting()
and
persisted()
(or
saving()
and
saved()
if you prefer)
updating()
and
updated()
removing()
and
removed()
(or
deleting()
and
deleted()
if you prefer)