Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form update of all connected sessions
#1
Hello

I have a use case when action in one form must refresh form components in all connected sessions. I can successfully update form components, but changes are not seen until web browser windows is refreshed (F5).

Executing WebApplication.ShowMessage properly pops up a message in all connected sessions.

Code:
procedure TFormMain.pRefreshForm;
begin
   WebApplication.ShowMessage('Session message'); // this message shown
   RegionMain.AjaxReRender();
end;


var LSessions : TList;
   LSession : TIWApplication;
   i : Integer;
begin
   LSessions := GSessions.LockList;
   try
       for i := 0 to Pred(LSessions.Count) do begin
           LSession := LSessions[i];
           LSession.Lock;
           try
               // to-do: check which form is opened

               TFormMain(LSession.ActiveForm).ImageUser.Picture.Url := 'xxx';
               TFormMain(LSession.ActiveForm).EditName.Text := 'User Name';
               TFormMain(LSession.ActiveForm).pRefreshForm; // message is shown, but form is not refreshed
               // TFormMain(LSession.ActiveForm).Update; // does not work
               // TFormMain(LSession.ActiveForm).Refresh; // does not work

           finally
               LSession.Unlock;
               // LSession.Redirect('http://127.0.0.1',True); // does not work
               LSession := nil;
           end;
       end;
   finally
       GSessions.UnLockList(LSessions);
   end;
end;

Please advise me if it is possible to execute refresh of all active forms bound to one web server.

ps: I am using IW 1.4 and cgdevtools components 14.2.

Regards,
Tomaž
Reply
#2
To do this you need to put an async timer on each form that might be open at the time and check for updates in that event.

Browsers do not support push notifications as it creates a lot of load on the webservers. There are JS libs to "hack" it but they have side effects. For now an universal compatibility, the timer is probably the best route but you will have to do it to each and every form that might be visible at the time and dont make the timing too short else you will also create a load for the server.
Reply
#3
I tried to add timer on form and start it in procedure pRefreshForm, but it had no effect. If I understand correctly you advise me to add a timer on a form and set it to be enabled all the time ? That is a problem because update frequency should be 1 second or 1 hour, depending on the situation. We would like to monitor entrances to the building where user image is displayed to the receptionist each time a person checks in. So frequency should be 1 second in peak time, when a lot of people are coming to the building and much less otherwise.

Any other idea ?


ps: how come that webapplication.showmessage is shown ?

Regards,
Tomaž
Reply
#4
(12-17-2018, 09:23 PM)cyracks Wrote: I tried to add timer on form and start it in procedure pRefreshForm, but it had no effect. If I understand correctly you advise me to add a timer on a form and set it to be enabled all the time ? That is a problem because update frequency should be 1 second or 1 hour, depending on the situation. We would like to monitor entrances to the building where user image is displayed to the receptionist each time a person checks in. So frequency should be 1 second in peak time, when a lot of people are coming to the building and much less otherwise.

Any other idea ?


ps: how come that webapplication.showmessage is shown ?

Regards,
Tomaž

Does this work in the async procedure?

 
Code:
 for i := 0 to ControlCount - 1 do
  Controls[i].Invalidate

Another suggestion:

Code:
 js: string;
begin
 js := 'var form =  window.document.forms["SubmitForm"];' +
       'if (form) {' +
       '  form.submit();' +
       '}';
 WebApplication.CallBackResponse.AddJavaScriptToExecuteAsCDATA(js);
end;

Both from Alex some time back.  I haven't needed them so haven't tried.

Dan
Reply
#5
How many concurrent sessions do you have?

IWMonitor component was designed to do things like that. IWMonitor watches a certain flag in WebApplication. When the flag is set, it triggers an action (which can be a page refresh, for instance). IWMonitor is lightweight (much more than the IWTimer) so it should be OK to use it even in 1 second intervals.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)