0

Possible Duplicate:
Problem calling grails service from gsp

I have a service called HeaderService that is in a package called application in a project called Portfolio. How can i import this service into a gsp? I have tried

<%@ page import="com.portfolio.application.HeaderService" %>

And many variations, but It doesnt work. Anyone have any suggestions? Thanks!

Community
  • 1
  • 1
daniel langer
  • 1,855
  • 2
  • 17
  • 20

1 Answers1

2

You can access your services through the applicationContext object that's implicitly available in views. Example:

<%= applicationContext.headerService.doSomething() %>
ataylor
  • 64,891
  • 24
  • 161
  • 189
  • 1
    Great, you told him how to do something horrible. – Gregg Jul 09 '12 at 21:35
  • 2
    I agree with your comment that it's bad practice. Fine. It's still useful to know how to do it. Sometimes, it's a convenient shortcut; a great example is the default `index.gsp` grails generates with `create-app` which uses this technique to get access to the `pluginManager`. – ataylor Jul 09 '12 at 22:33