In a programming scenario, I needed to check if my GWT textbox was focused or not. I ended up adding a boolean and a pair of Focus & BlurHandler to manually keep the focus state which makes me wonder why is there no such method that returns if a focusable component is focused in gwt?
Because there wasn't any cross-browser way of doing it until a few years ago (Firefox 3, Safari 4, to point at the last players in the game having added support document.activeElement
).
GWT still officially supports [1] Safari 3 (I believe Safari 2 support has been deprecated) and maybe even Firefox 2 (no DevMode plugin, but that doesn't mean the browser isn't supported: Opera is supported but has no DevMode either), so it's not possible to provide such a feature that would work in all supported browsers.
Last, but not least, I think no one ever filed a request for enhancement in the issue tracker (I couldn't find any at least); and as you said, you can already do it today using FocusHandler/BlurHandler (which works cross-browser).
[1] http://code.google.com/webtoolkit/doc/latest/FAQ_GettingStarted.html#What_browsers_does_GWT_support? I believe that page is a bit out of date, as it still lists Firefox 1.0, whose support (user.agent=gecko, vs. gecko1_8) has been removed in GWT 2.1.0, and doesn't list IE9, whose support has been added in GWT 2.3.0, and last but not least, I believe only the latest version of Opera is supported, whereas the list talks about Opera 9.
To find which widget has focus, I don't know whether you have solution already. As a novice to GWT , I propose my solution to share:
Declare private field in the object, like 'focusedWidget'
Create focus handler for the widget, here's class TextBox. In OnFocus block, just assign the widget to 'focusedWidget'. You can add this kind of event to every widget that can be focused. ![step 2][2]
I test it in JUnit
, it works!
see image of snippet here
Hope that help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With