Automatic Refreshing and the Watcher Classes

The Watcher class is used to connect a control to a database table or tables so that whenever that database changes, the control automatically refreshes. This can save you from having to setup callbacks between edit forms and dialogs in order to refresh a control that is viewing data. In addition, in a multi-user environment, when one user changes the data, the other user will automatically see the change. This is similar to what you might see in a system like NodeJS, with some caveats

The current implementation requires the browser to generate either an Ajax event or Server event in order to detect the change. In a multi-user environment, it the user is actively using your application, this should happen pretty often. However, if your application is such that the user might have long-periods of inactivity, but still should see the results of activity from other users, you can do a couple of things:

  • Set up a JsTimer to generate periodic events. See the JsTimer example page for help. In that example page, it discusses adding actions to the timer. For purposes of generating opportunities for the Watcher to look at the database, you will add a null ajax action to the timer.
  • The other option, which is currently not implemented in QCubed, is create a direct connection between the server and the user's browser that will trigger these events. There are a few different technologies to do this, and many require a customized html server. Apache will not do this out of the box. A messaging server like PubNub may be the best candidate for this.

To make a watcher work, you must edit the /project/qcubed/Watcher/Watcher.php file so that the Watcher class inherits from the watcher type you want. Available types currently let you use a database to track changes, or use a CacheProvider subclass.

This is another Datagrid example with a couple of fields to add a new person. Whenever you add a person, the person will appear in the datagrid immediately. It also has a timer to generate periodic events that will check whether another user has changed the database. Try opening the page in another browser on your computer to simulate a multi-user environment. Whenever you add data to one browser, it will appear in the other browser.

First Name
Last Name
JohnDoeooo
KendallPublic
BenRobinson
MikeHo
AlexSmith
WendySmith
KarenWolfe
SamanthaJones
LindaBrady
JenniferSmith
BrettCarlisle
JacobPratt
58
58
58
5741787887
JosephBiden
JosephBiden
JosephBiden
sdbvasdgvb
sdbvasdgvb
JohnDoe
JohnwwDoe
tttttttyyyyyy
tttttttyyyyyy
tttttttyyyyyy
tttttttyyyyyy
tttttttyyyyyy
tttttttyyyyyy

First:

Last: