Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

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

 
author and cow tipper
Posts: 5006
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5006
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5006
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5006
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5006
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Bartender
Posts: 2910
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic