webfirmframework for Java Experts
Lossless browser page communication in wffweb-12
It is available since 12.0.0. It is enabled by default. If it is enabled this is what happens, let's understand it by an example:
//some existing div in the UI
Div mainDiv = new Div(null);
Div div1 = new Div(null);
// step 1
mainDiv.appendChild(div1);
Div div2 = new Div(null);
// step 2
mainDiv.appendChild(div2);
Div div3 = new Div(null);
// step 3
div2.replaceWith(div3);
Suppose, the client received UI changes for the step 1 and
suddenly the network lost, the changes for step 2 was already sent
from the server but could not be delivered to the client. The
network reconnected and the client received changes for step 3.
The changes for step 3 and subsequent changes will be ignored
because the changes for step 3 is not valid as the changes for
step 2 is not applied on the UI, precisely
div2
is not available on the UI so it cannot be replaced with
div3
. After step 1, the client will execute the
JavaScript
code set in
BrowserPage.Settings.onPayloadLoss.javaScript
. The default value for the
JavaScript
is for reloading the browser page so the browser page will reload
just after executing step 1. This is what happens when client
loses a payload sent from the server.
The same scenario is applicable at server side. Suppose, there are
three buttons on the UI, button1 button2 and button3. Each button
has an
OnClick
event attribute java code. The user clicked on button1 and
button2, the
OnClick
event attribute of button1 is executed at server side but the
event changes for button2 could not be delivered to the server due
to network failure. The network reconnected, the user clicks on
button3 and the onclick event changes are delivered to the server
but the
OnClick
event of button3 will not be executed as the previous payload was
not delivered to server, i.e. the payload of button3 event and
subsequent events will not be processed instead it will execute
the action set in
BrowserPage.Settings.onPayloadLoss.serverSideAction
(just after executing
OnClick
of button1). The default
BrowserPage.Settings.onPayloadLoss.serverSideAction
is for reloading the browser page.
The
browserPage.defaultSettings()
can be used to get the default setting of the
BrowserPage
instance. To change the current
Settings
override
useSettings
method in the subclass of
BrowserPage
. getSettings
may be used to get the current settings (i.e. the applied settings by useSettings
method).
@Override
protected Settings useSettings() {
final OnPayloadLoss onPayloadLoss = new OnPayloadLoss(
"console.log('reloading page');location.reload();",
defaultSettings().onPayloadLoss().serverSideAction());
final Settings newSettings = new Settings(
defaultSettings().inputBufferLimit(), defaultSettings().inputBufferTimeout(),
defaultSettings().outputBufferLimit(), defaultSettings().outputBufferTimeout(),
onPayloadLoss);
return newSettings;
}
To disable this lossless browser page communication, pass
null
for
BrowserPage.Settings.onPayloadLoss