I used both.
It depends what kind of behaviour you want. Here's what I have in the
class that implements the onModuleLoad:
@Override
public void onPreviewNativeEvent (NativePreviewEvent preview)
{
if (closingRegistration == null)
// not logged in yet
return;
switch (preview.getTypeInt())
{
case Event.KEYEVENTS:
case Event.MOUSEEVENTS:
case Event.ONCLICK:
case Event.ONDBLCLICK:
case Event.ONMOUSEWHEEL:
logoutWarn.schedule(LoginModel.SESSION_TIMEOUT -
LoginModel.SESSION_WARN_TIMEOUT / LOGOUT_SPEED);
Controller.viewUpdated(Application.View.USER_ACTION, null);
break;
}
}
logoutWarn is just a Timer object that (the arithmetic there is just
for some animation stuff that warns the user there's a logout
approaching due to inactivity). Controller.viewUpdated simply sends
an RPC to the server telling it that there was a user action (i.e.
refresh the session on the server side). This isn't a direct RPC call
though. It keeps postponing the RPC call (which is done within a
timer) until a threshold is reached.
On the server side, I persist sessions in the database. Every RPC
call refreshes the session in the database. If a session is not
valid, that'll throw an specific exception - all RPC callbacks are
actually wrapped in a central callback that handles server errors
(i.e. if the server responds with not authenticated, it'll force a
logout of the UI).
Also, when the UI logs out due to inactivity, it sends an RPC call to
the server telling it the session has been invalidated (not strictly
necessary, but just a security thing) & removes any session related
cookies.
Hope this helps.