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 <wsal...@gmail.com> wrote:
> Adam, I added
>     <script src="protovis.js" />
> to the .gwt.xml.
>
> No change!
>
> On Jul 20, 4:24 pm, Adam T <adam.t...@gmail.com> 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 <wsal...@gmail.com> 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 trying this time to write a wrapper for another Visualization
> > > library, Protovis. An example JS use case is as follows:
> > > ********************
> > > HTML file
> > >     <script type="text/javascript" src="protovis.js"></script>
> > > JS file
> > >     var vis = new pv.Panel().canvas("PVis"); // <== future JSNI
> > > problems occur at this point
> > >     var line = vis.add(pv.Line);
> > >     // add data and attributes to line
> > >     vis.render();
> > > **********
> > > I write a GWT wrapper as follows
> > > ********************
> > > JAVA file
> > >     class PChart {
> > >       JavaScriptObject pvis;
> > >       public PChart( String id ) { pvis = _chart( id ); }
> > >       private native JavaScriptObject _chart( String id ) /*-{
> > >         return new $wnd.pv.Panel().canvas( id );  // <=== ERROR at
> > > this line
> > >       } -*/;
> > >       // other stuff
> > > **********
> > > The GWT compiler returns the following error at the indicated line
> > > ********************
> > > com.google.gwt.core.client.JavaScriptException: (TypeError): $wnd.pv
> > > has no properties
> > > **********
>
> > > I do not understand what I am doing wrong. Can someone help me to get
> > > this to work?
--~--~---------~--~----~------------~-------~--~----~
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