How do I (or should I?) access the service layer from a SiteMesh template (views/layouts/main.gsp) in Grails?

Posted by knorv on Stack Overflow See other posts from Stack Overflow or by knorv
Published on 2011-01-15T11:17:26Z Indexed on 2011/01/15 11:53 UTC
Read the original article Hit count: 210

Filed under:

I need to create a toplist in the page footer on a site that I'm building. The footer is created in the default SiteMesh layout template (views/layouts/main.gsp).

In order to create the toplist access to the database is needed, so I've encapsulated all logic needed for the toplist creation in a service class (services/FooService).

Please note that while services are usually accessed from the controller layer, in this case the default layout template (views/layouts/main.gsp) is not generated from a controller.

  • Can the layout view (views/layouts/main.gsp) access a service class? How?
  • Is this the correct design decision? If not, what is a better encapsulation and how do I interact with said encapsulation from the layout view (views/layouts/main.gsp)?

© Stack Overflow or respective owner

Related posts about grails