Can grails controller dynamically return an update to the view before the activity completes?

Current situation

I am executing an external application (using Runtime.getRuntime().exec

... example here ) and I am listening to Stream the application is writing to stdout. This part works as intended and I get the results (in the grails controller) line by line as they are available, and - when the stream has no more content - I do the result on the page.

Another aspect is to initiate this application asynchronously from the gsp page. This is also already covered and a call to remoteFunction is called (to the above controller method), the results are collected and returned, and they appear correctly in the selected area on the page.

But what annoys me and what I really want to achieve is:


to display the lines read from the stream as they are read, rather than after the entire stream has finished (as is done now).

This means (something like, for example) causing rendering for every line in the stream read loop:

while ((line = bri.readLine()) != null) {
  //render line here?


Can this be achieved?

Explain, please:)


source to share

1 answer

I think there is no standard grails method to achieve the desired behavior.

g: remoteFunction is still a tag that wraps the AJAX request for you. The request is limited to the request response pattern - you cannot get multiple responses for a single request. Your action code will not be automatically changed.

You have to implement it yourself.

I would try the following:

  • Split your single remoteFunction call into multiple AJAX requests .
  • The first request will initialize a new thread that your external application is listening on.
  • The results of this application must be stored in the session scope , so ...
  • the following periodic requests from the client can poll the current execution status.


All Articles