javagwtuibindercontext-sensitive-help

Context sensitive help in GWT application


I need to provide context sensitive help in my GWT application. For this every GWT view will have many help links each of which will open a dialog box with appropriate help text (different for each link). The problem is I cannot have so many ui:field elements each with unique name and click listener in my view classes as the number of help links may be very large. What I need is to have many Anchor elements in my UI binder xml file and all the anchors should have the same click listener. The click listener will decide based on some parameter which help text to display in the dialog box.

I tried to use Hyperlink element with different history tokens for all links, but it changes the history which is not desirable. I just want to show a dialog box with appropriate help message without modifying history.

Is it possible in GWT?

Thanks for your help.


Solution

  • You can obviously use <g:Anchor href="javascript:;"> in your UiBinder and later add handler in your code.

    But, since you have a lot of this all around your app I'd use gwtQuery:

    $(".help-link").click(new Function(){
          public void f(Element element) {
              // do something here
              // `element` tells you which element triggered the event        
    });
    

    then I'd just add css class .help-link to all relevant anchors.