Monday, September 27, 2010

Re: Calling GWT method from javascript

my guess is that the GWT code has not been loaded yet. try this:

<script type="text/javascript">
function sayHello(name) {
alert(hello(name))
}
</script>
</head>
<body onload="sayHello('fooBar');">

On Sep 27, 4:23 am, Murphy <connal.mur...@gmail.com> wrote:
> Hi,
> As the subject says, I'm having a problem calling a GWT method from
> Javascript.
>
> I'm pretty sure the GWT side of things is set up correctly because
> this works:
>    <button onclick="alert(hello('fooBar'))">Say Hello</button>
> So when I click on the button, my exported JSNI method (called
> 'hello') is correctly invoked and I see the alert.
>
> But the following code does not work
>     <script type="text/javascript">
>         alert(hello('fooBar'));
>     </script>
>
> Nor does this:
>     <script type="text/javascript">
>         function sayHello(name) {
>             alert(hello(name))
>         }
>         sayHello('fooBar');
>     </script>
>
> Instead, I just see an message in the Firebug console saying "hello is
> not defined"
>
> Any ideas as to what I'm doing wrong?
> As far as I can see, I've faithfully followed the instructions given
> in various places for what I'm trying to achieve (e.g.http://code.google.com/p/gwtchismes/wiki/Tutorial_ExportingGwtLibrari...)
>
> Any & all help appreciated ...
>
> Cheers,
> CM

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment