Auto-refresh page

This requirement from the users mailing list:

  • "Suppose you want to build a monitoring application, eg for an electricity grid. Data is updated in the background (eg via the Restful Objects REST API). What is needed is the ability to show an entity that includes a map, and have it auto-refresh every 5 seconds or so."

Here’s one (somewhat crude, but workable) way to accomplish this.

  • First, update the domain object to return custom CSS:

    public class MyDomainObject {
        ...
        public String cssClass() { return "my-special-auto-updating-entity"; }
        ...
    }
  • Then, use custom JavaScript to reload:

    scripts/application.js
    $(function() {
        if ($(".my-special-auto-updating-entity").length) {
            setTimeout(function() {document.location.reload();}, 5000); // 1000 is 5 sec
        }
    });