No, that's wrong since the GWT compiler won't actually define clickTest but
obfuscate it to save on bandwidth.  You cannot do it that way.

What you could do, if you were dead set on adding the HTML that way (if
you're going to do it that way, why not just put it into the original HTML
page?), you can do:


public void onModuleLoad() {
               RootPanel.get().add(new HTML("<h1 onclick=\"return
$wnd.h1ClickHandler();
\">TEST</h1>"));
}

private static native void registerOnClick() /*-- {
   $wnd.h1ClickHandler = function() {
          $wnd.alert("OK");
   }
} --*/;

Haven't tested but it should get you on the right track.  Optionally, you
could do it as:

private static native String createH1(String text) /*-- {
   return '<h1 onclick="jsni name of java function">' + text + '</h1>;
} --*/;

I would recommend you read & try to understand how JSNI works.

& the above is extremely redundant.  Why aren't you using regular GWT
widgets for this?  JSNI is really not recommended for use unless you can
explain why the same thing can't be accomplished in GWT.  If you use JSNI,
you're also more likely to cause memory leaks (pure GWT code will not leak
memory).

On Wed, Apr 15, 2009 at 12:56 AM, dayre <david.c.a...@gmail.com> wrote:

>
> I've been banging my head on this all day... i have a JSNI native
> method defined in my main EntryPoint class:
>
>        /**
>         * This is the entry point method.
>         */
>        public void onModuleLoad() {
>                RootPanel.get().add(new HTML("<h1 onclick=\"return
> clickTest();
> \">TEST</h1>"));
>        }
>
>        public native void clickTest() /*-{
>          $wnd.alert("OK");
>        }-*/;
>
> The page renders the TEST h1 HTML with the javascript onclick call but
> when i try to click on it, nothing happens... when i compile/browse
> and view in Firefox with firebug, firebug reports "clickTest is not
> defined".   I don't see the method defined anywhere in the generated
> code.
>
> Any ideas ?
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to