*
The moose likes GWT and the fly likes Using FocusWidget.addClickHandler for GWT 2.0 Hyperlink (ClickHandler deprecated) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » GWT
Bookmark "Using FocusWidget.addClickHandler for GWT 2.0 Hyperlink (ClickHandler deprecated)" Watch "Using FocusWidget.addClickHandler for GWT 2.0 Hyperlink (ClickHandler deprecated)" New topic
Author

Using FocusWidget.addClickHandler for GWT 2.0 Hyperlink (ClickHandler deprecated)

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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?

addClickHandler(ClickHandler handler)
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) ?



Thanks!

-Cameron McKenzie
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

I just Googled FocusWidget.addClickHandler and this post was the very first link returned from the seach engine.

Now my simple FocusWidget problem is turning into a problem of recursion...Someone help before I get a StackOverflow!

-Cameron McKenzie
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

I am continuing this conversation with myself.

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?

-Cameron McKenzie



Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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.

-Cameron McKenzie
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Hmmm....Thought I'd get clever and just remove the history link from the HyperLink and assign it to null.



I think it's my History that's causing the problem. So, this is what the compiler had to say about that:

java.lang.AssertionError: targetHistoryToken must not be null, consider using Anchor instead

So, this starts to answer my question about the difference between an anchor and a hyperlink. I guess an anchor doesn't need to create a history token, where a HyperLink must?

GWT Anchor JavaDoc

GWT Hyperlink JavaDoc
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 McKenzie


salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 917

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.

My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
 
Don't get me started about those stupid light bulbs.
 
subject: Using FocusWidget.addClickHandler for GWT 2.0 Hyperlink (ClickHandler deprecated)
 
Similar Threads
How about comparison with GWT and jQuery?
comprehension problem gwt & events
GWT for the enterprise?
Google Chrome and gwt
Does GWT-EXT have a Hyperlink Class? Where is they HyperLink class?