0

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?

  • Interceptors are not ideal as I need to check across just about all controllers
  • Filters are not ideal because on some screens with graphs there are many ajax request, the check would be run many times for each request.

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

dre
  • 1,027
  • 1
  • 11
  • 31

2 Answers2

2

A filter that disregards the check if a request header indicates an Ajax request would work.

Todd Sharp
  • 3,207
  • 2
  • 19
  • 27
1

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).

Joshua Moore
  • 24,706
  • 6
  • 50
  • 73
  • I eventually went down the route of using a taglib. I guess that makes your answer the closest to what I was looking for. Thanks. – dre May 02 '17 at 08:00