Search code examples
grailsgrails-pluginatmosphere

Grails atmosphere plugin problem


I'm using the Atmosphere plugin in a Grails application to make Ajax push calls to the client. The basic architecture is, I have a loop in the server which creates the data that I want to push to the browser, so in every iteration it uses the atmosphere broadcast() method to send the data to the client.

It works fine when I use it outside the loop, like this:

def builder = new JSONBuilder()
def jsonResult = builder.build{
        artist = "incubus"
        location = {
                lat = 45.678909
                lng = -14.45667
        }
    }

broadcaster['/atmosphere/recommend'].broadcast(jsonResult)

However, when I use it programmatically inside the loop, the browser throws the error: An invalid or illegal string was specified" code: "12, and doesn't work properly.

A simplified example of the loop is as follows:

[[lat:45.678909,lng:-14.45667],[lat:32.56433,lng:22.4566]].each{
        def builder = new JSONBuilder()
        def jsonResult = builder.build{
            artist = "incubus"
            location = {
                lat = '"${it.lat}"'
                lng = '"${it.lng}"'
            }
        }

        broadcaster['/atmosphere/recommend'].broadcast(jsonResult)
    }

Any ideas why is this happening? Thanks!


Solution

  • I think it should work, if you remove the quotes.

    location = {
        lat = it.lat
        lng = it.lng
    }
    

    Christian