|
Re: Auto refresh page [message #994912 is a reply to message #994891] |
Fri, 28 December 2012 16:13 |
|
This depends on what you want to achieve. There are basically two ways, the client can take actions "on its own":
- Notification: If you want the client to take some action when a certain event happens on the server, use a "client notification". See here and here for more information.
- Polling: If you want to simlate "periodically pressing F5" (e.g. to visually monitor some data), create and start your own client job. If that job is asynchronous (i.e. extends ClientAsyncJob) it is run as a background and is not visible to the user. When you want to change something in the Scout model (e.g. replacing all rows in a table), you have to get synchronous again. Here is a quick example:
...
// (add this code somewhere in the initialization part of your page)
new ClientAsyncJob("my async background job", ClientSession.get()) {
@Override
protected void runVoid(IProgressMonitor monitor) throws Throwable {
while (!stopCondition) {
// (***1***) Do some background work here, or just Thread.sleep(...)
new ClientSyncJob("synchronize with Scout model thread", ClientSession.get()) {
@Override
protected void runVoid(IProgressMonitor monitor) throws Throwable {
// (***2***) update Scout model, e.g. myPage.reload();
}
}.schedule();
}
}
}.schedule();
...
This pattern might look slightly confusing, but is actually quite common. Code at location ***1*** is executed in the background and may take long, while code ***2*** is executed in the foreground (visible to the user) and should not take too long (because other user actions have to wait until it's done).
Does that already help you?
|
|
|
|
Powered by
FUDForum. Page generated in 0.02972 seconds