So, I'm migrating to GWT 2.0, and my hyperlinks keeps getting yelled at for using the deprecated ClickHandler.
The JavaDoc says to use FocusWidget.addClickHandle. Why does the Hyperlink need to use this FocusWidget? Why can a Hyperlink not use a ClickHandler but a GWT Button and Anchor can?
I'm not sure how to use it? Does anyone have an example?
Deprecated. Use FocusWidget.addClickHandler(com.google.gwt.event.dom.client.ClickHandler) instead and call History.newItem from the handler if you need to process the click before the history token is set.
Here's my current code that takes a Hyperlink named hyperLink and adds a ClickHandler. How would I recode this to use FocusWidget.addClickHandler(ClickHandler) ?
Interesting, but I read a comment somewhere that said to someone "maybe you should be using a GWT Anchor instead of a GWT Hyperlink." The hyperlink was not only giving me deprecation messages, but it also was taking me to a wrong screen, although it was correctly doing CardDeck transitions, so when you went back to the page you were supposed to be at, it was being displayed properly - just buried by another screen. Anyways, I said to myself "Self, maybe you should be using a GWT Anchor?"
When I used the Anchor, my ugly deprecation messages about the ClickHandler went away:
Now to see if it provides the behavior I'm looking for?
Well, my code looks prettier with the anchor, but the functionality goes away. I click on the anchor, I see the correct widget/panel appear, and then I'm taken back to the original showcase panel, and my application starts over again. So, the code looks better, but the application becomes buggier.
In an attempt to hijack my own thread, I am now wondering what is the difference between a GWT Anchor vs Hyperlink? Hmmm...
Now I'm going to shove a button in there in addition to the Hyperlink and Anchor.
Hyperlink: A widget that serves as an "internal" hyperlink. That is, it is a link to another state of the running application. When clicked, it will create a new history frame using History.newItem(java.lang.String), but without reloading the page.
Being a true hyperlink, it is also possible for the user to "right-click, open link in new window", which will cause the application to be loaded in a new window at the state specified by the hyperlink.
It does look like the improper handling of my History token was to blame for my quirkiness. Both the Button and Anchor without a history token provided the behavior I wanted:
So, I managed to fix the application by avoiding the original problem, which is really just an issue of how to properly use the GWT API, and more to the point, how to program Java. So, the question remains, does anyone have a sample of code that uses the FocusWidget.addClickHandler to add an event handler to a GWT Hyperlink, since we can't use the deprecated ClickHandler???
BTW, it's been fun chatting with myself this Saturday afternoon. What a great thread: images, pictures, code, runtime bugs, compiler errors, hyperlinks, and all esoterically assembled without an answer to the original conundrum? A work of art to be admired by the romantics, if I do say so myself.
Cameron Wallace McKenzie wrote: BTW, it's been fun chatting with myself this Saturday afternoon. What a great thread: images, pictures, code, runtime bugs, compiler errors, hyperlinks, and all esoterically assembled without an answer to the original conundrum? A work of art to be admired by the romantics, if I do say so myself.
Very interesting man,
I confess if i had updated myself to gwt2.0, i would have definitely helped you in this issue....
All that i know is that in GWT 1.5,
A hyperlink triggers an history event compulsorily, The only way i could circumnavigate this was by using an HTML widget containing "<a href='something'>text</a>"
These do not generate history events.