Best to use the tag library because creating a service instance directly in the view via the class loader WILL NOT autowire other services declared that may live in the service you are trying to use.
Using the tag library you will have auto-wiring of those services.
In your gsp view <g:customTag param1="$modelObjec" param2="someString" />
In your taglib folder (yourApp/grails-app/taglib/com/something/MyAppTagLib
):
package com.something
class MyAppTagLib {
def myService // This will be auto-wired
def customTag = { attribs ->
def modelObj = attribs['param1']
def someString = attribs['param2']
// Do something with the params
myService.method()
out << "I just used method of MyService class"
}
}
Your MyService:
package com.something
class MyService {
def anotherService // This will be auto-wired
def method() {
anotherService.anotherMethod()
}
}