tags:

views:

182

answers:

2

I have a domain class containing a couple of fields. I can access them from my .gsps. I want to add a method to the domain class, which I can call from the .gsps (this method is a kind of virtual field; it's data is not coming directly from the database).

How do I add the method and how can I then call it from the .gsps?

+7  A: 

To add a method, just write it out like you would any other regular method. It will be available on the object when you display it in your GSP.

def someMethod() {
return "Hello."
}

Then in your GSP.

${myObject.someMethod()}
Hates_
+1  A: 

If you want your method to appear to be more like a property, then make your method a getter method. A method called getFullName(), can be accessed like a property as ${person.fullName}. Note the lack of parentheses.

John Flinchbaugh