Search code examples
javagwthistorygwt-history

Login problem with GWT History


I have the follow problem. This is the situation i've got when user login the application and register History. The workflow is: 1. There is a checking if user is already login- meaning if user object is in the session if not then login form is loaded and a new token is added (History.newItem("login")) if yes then the user is free to enter the main form in the application and a token is added (History.newItem("main")). After user enter pass and user successfully then a new token is added (History.newItem(main)) and enter the application main form.

And here is the problem, after main form is displayed and user decide to click "Back" in the browser then "login" token is taken from the stack and login form is loaded. But let assume user decide to click on "Forward " browser button and then "main" token is taken and main form displayed. I don't like this scenario and want to do : After "back" button to appear a Dialog box and ask "Leave application?" with "Yes" and "No" button but i can't identify when i have regular login or "back/forward" login in order to do some action.

Any advice or approaches.. probably my design is wrong..

Any way to distinguish back or forward action?


Solution

  • If you want to avoid all this then don't put "login" in history.

    In this case you might want to implement login panel as modal dialog. So when user (or application) requests login, a modal dialog is shown with login entry field. When done with login, just close the dialog and reload the current page (to reflect the changes affected by login).

    You can use 'History.fireCurrentHistoryState()' to force reloading the current page. This calls your history handlers, but it does not affect the history (no token is added to history stack).