How to handle browser event in gwt?

519 views
Skip to first unread message

Sanjay Jain

unread,
Nov 10, 2011, 4:03:19 AM11/10/11
to Google Web Toolkit
I am using GWT 2.3 with GWTP plugin in my application.In this
application I want to block browser back and forth event.For this I
got some java script code.But this code is onLoad() and onUnLoad() of
the html page.As application is a GWT application there is only one
html which myapplication.html.So it is loaded only one time rest
history token fire depends upon code. I want to block browser event
for each and every history token in the system.

Scenario is like below:

My first history token is index.So first my index page is loaded.Now
there is login panel on index page.After success full login I fire
another history token named userpage.So my user page is loaded.On back
click a history token index is fired again my index page loaded
again.And now If I click on forth of browser then again my user page
is loaded.

So for back I don't want to fire last history token again and same for
the forth not next history token. If history token would fired from
code instead of browser event (back and forth) then it should work in
proper manner.So just want to handle browser event.

For handling history I also overridden method on value change.So my
every history token is went to on Value change but I am not able to
identify, that the history token is fired is from browser event or
from code.

Please help me out. Thanks in advance.

Thomas Broyer

unread,
Nov 10, 2011, 5:52:48 AM11/10/11
to google-we...@googlegroups.com


On Thursday, November 10, 2011 10:03:19 AM UTC+1, Sanjay Jain wrote:
I am using GWT 2.3 with GWTP plugin in my application.In this
application I want to block browser back and forth event.

Maybe you didn't choose the right platform for the job then. When developping a web app, your user can navigate at any time within your app (and not only to the "previous page", he can go back several pages back in time, and/or use a bookmark), he can "terminate" it at any time too (either by navigating away, or closing the tab/window, or reloading it). Embrace these facts, don't fight again them (I can guarantee that you and your users will lose); they are features of web apps, not constraints.
It's a real switch in paradigm from desktop apps, but a necessary one (fwiw, Android apps have similar behaviors to web apps too).

My first history token is index.So first my index page is loaded.Now
there is login panel on index page.After success full login I fire
another history token named userpage.So my user page is loaded.On back
click a history token index is fired again my index page loaded
again.And now If I click on forth of browser then again my user page
is loaded.

So for back I don't want to fire last history token again and same for
the forth not next history token. If history token would fired from
code instead of browser event (back and forth) then it should work in
proper manner.So just want to handle browser event.

For handling history I also overridden method on value change.So my
every history token is went to on Value change but I am not able to
identify, that the history token is fired is from browser event or
from code.

Please help me out. Thanks in advance.

Depending on your needs (is authentication mandatory to use the app?) and wants re. UX, I'd suggest, either:
  • do login outside the app, on a separate page (just like Google Apps); so when the app is "started", either the user is authenticated, or it's not.
  • do not use a distinct history token for your login form; use events on your eventbus instead (not navigation events).
Or simply give up on trying to fight this behavior and just live with it; is it a real issue for your app?

OK, technically, you could also replace the current URL when navigating to/from your login form; but GWT doesn't support it (not that it's impossible, just that it doesn't provide APIs to do it; Glosure Library for instance has what would be equivalent to a History.replaceToken() in addition to History.newItem()).
Reply all
Reply to author
Forward
0 new messages