Hi, Adam. Thanks a lot for your effort! I found a way to eliminate the
problem, namely by directly compiling for web mode, and not for hosted
mode (I am still on GWT 1.5. I know, it is high time I ported!).

I do not understand it though. When I include raw JS files from the
Google Visualization API, the GWT compiler for hosted mode does not
complain, i.e. no errors/exceptions for
   $wnd.google.visualization....
But in the case of Protovis
   $wnd.pv
up pops a com.google.gwt.core.client.JavaScriptException.

Any ideas why?

waqar :)

On Jul 21, 5:39 pm, Adam T <[email protected]> wrote:
> .....perhaps you have the Javascript library in the wrong place and it
> is not being loaded.  I'd still suggest you get hold of a debug tool
> in your browser to see what's loaded etc as you're going to need it
> when you get into trying to access the library and going further, but,
> the following works for me to access the library.
>
> 1.  In my applications .gwt.xml file I have put: <script src="protovis-
> r2.6.js"/>
> 2.  I also have defined my module in the .gwt.xml file as follows:
> <module rename-to='testAA'>
> 3.  I'm using GWT1.6, so the protovis-r2.6.js file needs to go in
> within the war file, i.e. it goes in the folder /war/testAA/
> 4.  In my application I just create a simple JSNI method
>
>         public native JavaScriptObject getVis()/*-{
>                 var vis = new $wnd.pv.Panel().canvas("test");
>                 return vis;
>         }-*/;
>
> 5.  In my onModuleLoad I simply call the method and alert the fact
> that I have an object
>
>         public void onModuleLoad() {
>                 JavaScriptObject v =  getVis();
>                 Window.alert(v.toString());
>         }
>
> that tells me I have got a valid JavaScript object and I see no
> exceptions or errors.
>
> Hope that helps, or at least gives you some hints.
>
> //Adam
>
> On 21 Juli, 16:23, wsaleem <[email protected]> wrote:
>
> > I checked the link. Overlay types could surely make my life easier in
> > terms of wrapping Protovis but as long as I cannot access $wnd.pv
> > through JSNI, I cannot use them.
>
> > On Jul 20, 11:28 pm, wsaleem <[email protected]> wrote:
>
> > > 2) is the pure JS scenario, which I trying to port to GWT using JSNI.
> > > I fail, though, as the very first command
> > >       vis = new $wnd.pv.Panel().canvas("PVis");
> > > fails with the following JavaScript exception
> > >       $wnd.pv has no properties
> > > I will see if the overlay types help. Thanks for the pointer!
>
> > > On Jul 20, 7:48 pm, Adam T <[email protected]> wrote:
>
> > > > It could still be a similar thing; I'm not 100% clear what you are
> > > > trying to do above, but it looks like your steps are:
>
> > > > 1) Load an external JavaScript library, e.g. "protovis.js"
> > > > 2) Run some other JavaScript which creates something in the DOM, e.g.
> > > > the vis = new pv.Panel().canvas("PVis"); .....vis.render(); part
> > > > 3) In GWT access the rendered PVis component.
>
> > > > If that's correct, then by moving the "protovis.js" to the .gwt.xml
> > > > part your ensuring that the library loads before your GWT, but it is
> > > > still possible that part (2) is executing after your GWT code, and
> > > > hence it is not available to your GWT code when it runs.  You could
> > > > wrap that code in it's own file and load through the <script> tag
> > > > (though I'm not sure about ordering in the gwt.xl file).
>
> > > > I'd also suggest you use some debugging tools (Firebug for example in
> > > > Firefox) to look at what your code is doing, that should show you the
> > > > scoping of pv etc.
>
> > > > (though you might be better off writing a wrapper using JavaScript
> > > > Overlay types (http://googlewebtoolkit.blogspot.com/2008/08/getting-to-
> > > > really-know-gwt-part-2.html) that would let you merge GWT and the
> > > > protovis library in a more natural style, than the approach you're
> > > > taking just now)
>
> > > > Good luck,
>
> > > > //Adam
>
> > > > On 20 Juli, 17:41, wsaleem <[email protected]> wrote:
>
> > > > > Adam, I added
> > > > >     <script src="protovis.js" />
> > > > > to the .gwt.xml.
>
> > > > > No change!
>
> > > > > On Jul 20, 4:24 pm, Adam T <[email protected]> wrote:
>
> > > > > > Hi,
>
> > > > > > It might be the case that in both cases your GWT code is loaded and
> > > > > > executing before the browser has loaded your externally referenced
> > > > > > JavaScript file.  To remove that possiblity, you can place the
> > > > > > <script> tag you have in the HTML into your module's .gwt.xml
> > > > > > definition, i.e.
>
> > > > > > <module>
> > > > > >    <inherits name='com.google.gwt.user.User' />
> > > > > >    <script type="text/javascript" src="protovis.js">
> > > > > > </module>
>
> > > > > > With this sett up, the GWT boostrap code should ensure the library
> > > > > > JavaScript is loaded before your GWT code executes.
>
> > > > > > //Adam
>
> > > > > > On 19 Juli, 18:19, wsaleem <[email protected]> wrote:
>
> > > > > > > I am not a JS developer and use it pretty much by example, so it 
> > > > > > > might
> > > > > > > be that I am missing something really basic below.
>
> > > > > > > I have come across problems using JSNI in the following 2 
> > > > > > > scenarios:
>
> > > > > > > 1.
> > > > > > > I use Google Visualization API successfully in JS as follows:
> > > > > > > ********************
> > > > > > > HTML file
> > > > > > >     <script type="text/javascript" 
> > > > > > > src="http://www.google.com/jsapi";></
> > > > > > > script>
> > > > > > > JS file
> > > > > > >     google.load('visualization', '1', {'packages':['piechart']}); 
> > > > > > >  //
> > > > > > > <== future JSNI problems occur here
> > > > > > >     var chart = new google.visualization.LineChart
> > > > > > > (document.getElementById('GoogleVisChart'));
> > > > > > >     // other JS commands to draw the chart
> > > > > > > **********
> > > > > > > and then try to write a wrapper using GWT JSNI as follows:
> > > > > > > ********************
> > > > > > > HTML file
> > > > > > >     <script type="text/javascript" 
> > > > > > > src="http://www.google.com/jsapi";></
> > > > > > > script>
> > > > > > > JAVA file
> > > > > > >     class GChart {
> > > > > > >       static { _init(); }
> > > > > > >       private static native void _init() /*-{ // <=== ERROR at 
> > > > > > > this
> > > > > > > function
> > > > > > >         $wnd.google.load('visualization', '1', {'packages':
> > > > > > > ['piechart']});
> > > > > > >       }-*/;
>
> > > > > > >       JavaScriptObject gvis;
> > > > > > >       public GChart( String id ) { gvis = _chart( id ); }
> > > > > > >       private native JavaScriptObject _chart( String id ) /*-{
> > > > > > >         return new $wnd.google.visualization.LineChart
> > > > > > > ($wnd.document.getElementById( id ) );
> > > > > > >       }-*/;
> > > > > > >       // methods to draw the chart through native functions
> > > > > > > **********
> > > > > > > The GWT compiler gives the following error for the above code
> > > > > > > ********************
> > > > > > > [ERROR] Unable to load module entry point class
> > > > > > > com.google.gwt.app.testGViz.client.TestGViz (see associated 
> > > > > > > exception
> > > > > > > for details)
> > > > > > > java.lang.RuntimeException: Failed to invoke native method:
> > > > > > > @com.google.gwt.app.testGViz.client.GChart::_init() with 0 
> > > > > > > arguments.
> > > > > > >         at 
> > > > > > > com.google.gwt.dev.shell.moz.LowLevelMoz.invoke(LowLevelMoz.java:
> > > > > > > 132)
> > > > > > >         at com.google.gwt.dev.shell.moz.ModuleSpaceMoz.doInvoke
> > > > > > > (ModuleSpaceMoz.java:98)
> > > > > > >         at 
> > > > > > > com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:
> > > > > > > 447)
> > > > > > >         at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid
> > > > > > > (ModuleSpace.java:248)
> > > > > > >         at 
> > > > > > > com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid
> > > > > > > (JavaScriptHost.java:107)
> > > > > > >         at 
> > > > > > > com.google.gwt.app.testGViz.client.GChart._init(GChart.java)
> > > > > > >         at 
> > > > > > > com.google.gwt.app.testGViz.client.GChart.<clinit>(GChart.java:7)
> > > > > > >         at 
> > > > > > > com.google.gwt.app.testGViz.client.TestGViz.onModuleLoad
> > > > > > > (TestGViz.java:21)
> > > > > > >         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native 
> > > > > > > Method)
> > > > > > >         at sun.reflect.NativeMethodAccessorImpl.invoke
> > > > > > > (NativeMethodAccessorImpl.java:39)
> > > > > > >         at sun.reflect.DelegatingMethodAccessorImpl.invoke
> > > > > > > (DelegatingMethodAccessorImpl.java:25)
> > > > > > >         at java.lang.reflect.Method.invoke(Method.java:597)
> > > > > > >         at 
> > > > > > > com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:320)
> > > > > > >         at 
> > > > > > > com.google.gwt.dev.shell.BrowserWidget.attachModuleSpace
> > > > > > > (BrowserWidget.java:329)
> > > > > > >         at 
> > > > > > > com.google.gwt.dev.shell.moz.BrowserWidgetMoz.access$100
> > > > > > > (BrowserWidgetMoz.java:35)
> > > > > > >         at com.google.gwt.dev.shell.moz.BrowserWidgetMoz
> > > > > > > $ExternalObjectImpl.gwtOnLoad(BrowserWidgetMoz.java:59)
> > > > > > >         at 
> > > > > > > org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native
> > > > > > > Method)
> > > > > > >         at 
> > > > > > > org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:
> > > > > > > 1428)
> > > > > > >         at 
> > > > > > > org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2840)
> > > > > > >         at 
> > > > > > > com.google.gwt.dev.GWTShell.pumpEventLoop(GWTShell.java:720)
> > > > > > >         at com.google.gwt.dev.GWTShell.run(GWTShell.java:593)
> > > > > > >         at com.google.gwt.dev.GWTShell.main(GWTShell.java:357)
> > > > > > > **********
> > > > > > > Moving the statement in the native _init function to the 
> > > > > > > constructor
> > > > > > > does not help either. To get it to work, I have to move it out to 
> > > > > > > the
> > > > > > > HTML file
> > > > > > > ********************
> > > > > > > HTML file
> > > > > > >     <script type="text/javascript" 
> > > > > > > src="http://www.google.com/jsapi";></
> > > > > > > script>
> > > > > > >     <script type="text/javascript">
> > > > > > >         google.load('visualization', '1', 
> > > > > > > {'packages':['piechart']});
> > > > > > >     </script>
> > > > > > > **********
> > > > > > > This was also suggested 
> > > > > > > inhttp://groups.google.com/group/Google-Web-Toolkit/browse_thread/threa...
> > > > > > > Although this works, I do not understand why I could no do the
> > > > > > > google.load through JSNI.
> > > > > > > In the meanwhile, this is not an issue as GWT now provides its own
> > > > > > > wrappers for the Google Visualization API. But, I would still 
> > > > > > > like to
> > > > > > > understand the error.
>
> > > > > > > 2.
> > > > > > > I am
>
> ...
>
> read more »
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to