After researching, I discovered that in order to Log Out of the application, one must close the window with the following code snippet:
If you are looking for a solution, you can find it in this answer: How to run JavaScript function from GWT Java with JSNI?
Specifically for Java:
myButton.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
closeWindow();
};
});
public static native void closeWindow() /*-{ $wnd.closeWindow();}-*/;
Then, in JavaScript within your application's .html page:
<script type="text/javascript" language="javascript">
function closeWindow() {
window.open('','_self','');
window.close();
</script>
Incorporating this into my application:
//Log Out Button
Button logOutButton = new Button("Log Out");
logOutButton.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
closeWindow();
}
});
public static native void closeWindow() /*-{ $wnd.closeWindow();}-*/;
And the accompanying HTML:
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Wrapper HTML for AwardTracker</title;
<script src="org.AwardTracker.AwardTracker/org.AwardTracker.AwardTracker.nocache.js">
<type="text/javascript">
function closeWindow() {
window.open('','_self','');
window.close();
}
</script>
</head>
<body>
<iframe id="__gwt_historyFrame" style="width:0;height:0;border:0"></iframe>
</body>
</html>
Despite implementing this code, I encountered an error on the lines:
closeWindow();
Saying, "The method closeWindow() is undefined for the type new ClickHandler(){}"
public static native void closeWindow() /*-{ $wnd.closeWindow();}-*/;
This issue has multiple markers which need to be addressed. Furthermore, I received valuable feedback on using sessions (via RemoteServiceServlet) in my application. Therefore, based on the suggestions provided, I attempted the following:
On the client side:
logOutButton.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
//Invalidate the session and then reload the application.
AsyncCallback<Void> callback = new InvalidateSessionHandler<Void>(SelectPersonView.this);
rpc.invalidateSession(callback);
}
});
class InvalidateSessionHandler<T> implements AsyncCallback<Void> {
SelectPersonView view;
public InvalidateSessionHandler(SelectPersonView view) {
this.view = view;
}
public void onFailure(Throwable ex) {
System.out.println("RPC call failed - InvalidateSessionHandler - Notify Administrator.");
Window.alert("Connection failed - please retry.");
}
public void onSuccess(Void result) {
//Reload the application.
Window.Location.assign("/");
}
}
On the server side:
public void invalidateSession() {
getThreadLocalRequest().getSession().invalidate(); // kill session
}
Although this implementation seems to be effective, I am struggling to test multiple sessions locally without a test server for deployment. I humbly request assistance from someone experienced in this area to validate my approach and ensure it does not introduce any production issues. My main concern is inadvertently logging out all users, especially after encountering a data visibility issue due to unsegregated sessions in the past. This issue has been resolved, and I am keen to avoid any regression in this fix!