ajaxgrailswebsocketgrails-2.5

Grails - execute check on every request


I’m looking for a neat way to execute a check to see if there are any messages in an inbox (realtime) in a Grails 2.x application. I’ve moved away from polling via ajax to websockets, which is great at the point where someone actually sends you the message, but when you change to another screen, the “count” still needs to be initialized. Can anyone advise on a elegant way of doing this?

I’m wondering if there are any other solutions that I’m not thinking of.. but possibly not.


Solution

  • Depending on where you need this "count" you could: In your layout (main.gsp for instance) call a tag library which makes use of a service to fetch the count. That way it's only applied to GSPs where the layout is applied (e.g. not any ajax request).