« Return to Thread: Can I over-ride the getProperty function?
Thank you. I was getting errors
when I tried to do that, but it turns out it had something to do with the way I
was collecting the objects, it’s just that the error didn’t make any sense, so
I didn’t know if I could do that.
Thanks!
From: Jay Guidos
[mailto:jay.guidos@...]
Sent: Thursday, May 15, 2008 1:18 PM
To: user@...
Subject: RE: [grails-user] Can I over-ride the getProperty function?
Hi Pam,
Yes you can override any property getter for a class in the usual
groovy/java way.
There are several ways you can create a default value for a
property directly in the grails GORM class:
/** implicit virtual initializer */
class MyDomainObj {
String myProp = “aDefault”
}
/** explicit virtual initializer */
class MyDomainObj {
String myProp
{
myProp = “aDefault”
}
}
For your function that starts with ‘get’, there is no requirement
that you have a corresponding property. The JavaBean conventions are that
if you have a method that follows the pattern:
public <return value> getXXX()
then it will be considered to be the readable property XXX of type
<return value>.
Jay Guidos
From: Callaway, Pamela
[mailto:pcallaway@...]
Sent: Thursday, May 15, 2008 9:26 AM
To: user@...
Subject: [grails-user] Can I over-ride the getProperty function?
Hi folks,
Is it possible to over-ride a property “getter” for a
class?
Or should I use a constructor or something to fill up a
particular property, if it doesn’t come directly from the database?
Also, I noticed I have one function that starts with get,
even though I don’t have a corresponding property, and it still gets
created/shown as a property in the view. Interesting – is there a reason
for that?
Thanks,
Pam
« Return to Thread: Can I over-ride the getProperty function?
| Free Forum Powered by Nabble | Forum Help |