rcanovas rcanovas - 1 month ago 12
Java Question

Render view while processing data

I'm on Play Framework 2.5.14, with play for java.

I have a Service that loads and processes some data, and it takes a long time to process that data.

I'm doing it this way:


public Result showData() {
List<Data> data = service.getProcessedData();

return ok(views.html.data.render(data));


@(data: List[Data])

<!-- html code -->

But when I go to the page it is in blank a long time because
takes too long. When the function finish, then the view is rendered.

What I need is for the view to load and when the data is ready, fill the view.

Answer Source

Like I said in comments, I did not find a solution using Play.

What I do is to render the view, and in the view itself I call an ajax petition in javascript/jquery to get the slow data.

Hope this can help, it is the only solution that I liked.