Pregunta

I'm learning Grails, and have this web application.

I start with a view that has a form with a field like: <g:field name="phoneNumber"/>

This form submits to a controller that has a long process (it's running sip load on a phone number). I run this process asynchronously (using grails executor plugin).

class SipcallController {
    def placeCall() { 
        runAsync {
          if(params?.textCall) {
            def sipcli = "sipcli ${params.phoneNumber} -d ${params.env} -l 3 -t ${params.textCall}".execute()   
            [view_data:sipcli.text]
          } else {
            render "No Value Entered"
          } 
        }
    }
}

It works. The User doesn't have to wait for the sip phone call (previously they would wait until the controller's phone call was done then go to the results page to see the data).

They are now sent to a results page. However, I want to display the values from the controller once it's done in the same view they are at (results page.)

If I Put something like ${view_data} in the page it will error on page load saying "can't call method on null object" because the method doing the phone call isn't finished yet.

The Question:

How can I load the view put a wait on a tag, so that the data is loaded when the controller's process is finished? Can I do something like <g:WaitFor({$view_data})> ? I haven't got something like that to work.

¿Fue útil?

Solución

If you are trying to push data to the view after the process is done on the background you might need to use one of the AjaxPush/Comet or WebSocket frameworks. Take a look at Atmosphere Plugin or cometd Plugin see if these can help you accomplish what you want.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top