tags:

views:

37

answers:

2

Hi,

what is the best way to implement some action that should be executed each time a request is made?

My aim is to export some variables layout-wide, so the layout could render some fields like "You are logged in as ${userName}, Server time is ${serverTime}".

I know I can inline code in the gsp, but there should be some better way to execute some operations on each request.

Thanks in advance.

A: 

You could use layouts and SiteMesh to do that automagically, but in my project, I've stopped using that, because it also has some drawbacks (like <body onload="foobar()"> no longer working...). I propose you create a template just for this info line and render it wherever appropriate.

ammoQ
are you adding ${pageProperty(name:'body.onload')} to your decorator? Your body's onload should trigger correctly if you have it pulled into the decorator.
Rich Kroll
A: 

I've just found an answer here: http://stackoverflow.com/questions/503279/accessing-the-model-from-a-layout-view-in-grails

Filters is the way to execute some global action.

Max