unable to use external javascript in GWT

226 views
Skip to first unread message

Sandeep Poonia

unread,
Jul 27, 2014, 4:11:22 AM7/27/14
to google-we...@googlegroups.com
Hi ,
I want to use goJS with GWT. I downloaded GOJS javascript and put it in the sampleproject folder under war where sampleproject.nocache.js and sampleproject.devmode.js is present. In sampleproject.html i added 
<script type="text/javascript" language="javascript" src="sampleproject/go.js"></script>

In one of the view i used 
public static native void initGo() /*-{
var $$ = go.GraphObject.make;
}-*/;
when i call this function , exception is thrown:

com.google.gwt.event.shared.UmbrellaException: Exception caught: (ReferenceError) @com.amazon.ops.client.OpsMenuView::initGo()([]): go is not defined.

Can anyone please help me with this?

thanks,
sandeep

Jim Douglas

unread,
Jul 27, 2014, 3:51:10 PM7/27/14
to google-we...@googlegroups.com
Try it like this:

public static native void initGo() /*-{
var $$ = $wnd.go.GraphObject.make;
}-*/;

Also, you can add external js to your GWT project by dropping the files into your project/public/ directory and adding them to your project.gwt.xml file like this:


  <!-- External JavaScript http://html2canvas.hertzen.com/        -->

  <script src="html2canvas.min.js"/>


  <!-- External JavaScript JQuery UI Tooltip http://jqueryui.com/ -->

  <script src="jquery-1.11.1.min.js"/>

  <script src="jquery-ui.min.js"/>

  <stylesheet src="jquery-ui.min.css"/>

  <stylesheet src="jquery-ui.structure.min.css"/>

Thomas Broyer

unread,
Jul 27, 2014, 5:13:47 PM7/27/14
to google-we...@googlegroups.com


On Sunday, July 27, 2014 10:11:22 AM UTC+2, Sandeep Poonia wrote:
Hi ,
I want to use goJS with GWT. I downloaded GOJS javascript and put it in the sampleproject folder under war where sampleproject.nocache.js and sampleproject.devmode.js is present. In sampleproject.html i added 
<script type="text/javascript" language="javascript" src="sampleproject/go.js"></script>

You shouldn't put the file there. The sampleproject/ folder will be cleared by the GWT Compiler.
Either put your script in your "public path" so it gets copied there by the GWT Compiler [1], or put it outside the sampleproject/ folder.
 

In one of the view i used 
public static native void initGo() /*-{
var $$ = go.GraphObject.make;
}-*/;
when i call this function , exception is thrown:

com.google.gwt.event.shared.UmbrellaException: Exception caught: (ReferenceError) @com.amazon.ops.client.OpsMenuView::initGo()([]): go is not defined.

Can anyone please help me with this?

As Jim already said, you need to use $wnd to escape the sandbox GWT is running in and into the context of the web page, where your script is loaded.

Sandeep Poonia

unread,
Jul 30, 2014, 5:20:06 AM7/30/14
to google-we...@googlegroups.com
Thanks Jim and Thomas, $wnd worked for me. But i am facing problem when i changed the location of the go.js , I moved it to the folder where gwt.xml file is present using  <script src="go.js"/> but i am getting the following message. 

14:40:05.077 [ERROR] [opsdashboardlocal] The Cross-Site-Iframe linker does not support <script> tags in the gwt.xml files, but the gwt.xml file (or the gwt.xml files which it includes) contains the following script tags: 
go.js
In order for your application to run correctly, you will need to include these tags in your host page directly. In order to avoid this error, you will need to remove the script tags from the gwt.xml file, or add this property to the gwt.xml file: <set-configuration-property name='xsiframe.failIfScriptTag' value='FALSE'/>

And I am also confused about public folder. Should i create a public folder under my project or under src dir? 

Slava Pankov

unread,
Jul 31, 2014, 12:41:20 AM7/31/14
to google-we...@googlegroups.com
public folder should be on the same level as gwt.xml file. superdev mode doesn't allow usage of <script> in gwt.xml, you have to include it in your application html file (it will be copied from public folder to target). You still can inject your scripts in onModuleLoad() of your library, but it's quite tricky.
Reply all
Reply to author
Forward
0 new messages