|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
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 |
|
|
Re: Can I over-ride the getProperty function?Yeah, you can override a property by using "getProperty()" http://groovy.codehaus.org/Using+invokeMethod+and+getProperty
I'd imagine the issue with "get" in the view has something to do with JSTL, but I'm not sure. I think JSTL will just look for getBlah() whenever you do something like ${obj.blah}. -Dustin On Thu, May 15, 2008 at 11:25 AM, Callaway, Pamela <pcallaway@...> wrote:
|
|
|
RE: 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@...] 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 |
|
|
RE: 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@...] 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@...] 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 |
| Free Forum Powered by Nabble | Forum Help |