1

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.

bezmax
  • 25,562
  • 10
  • 53
  • 84

2 Answers2

1

I've just found an answer here: Accessing the model from a layout view in Grails

Filters is the way to execute some global action.

Community
  • 1
  • 1
bezmax
  • 25,562
  • 10
  • 53
  • 84
0

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.

Erich Kitzmueller
  • 36,381
  • 5
  • 80
  • 102
  • 1
    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 Oct 28 '09 at 13:11