Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

how to add javascript file and in script tags

Tudor Raneti
1 decade ago Oct 03, 2011 4:45pm

There's some weird flow specifications with paypal digital goods:
HERE
further down the page, requiring you to add a js file. I rather not add this unless the user is participating in the flow, and preferably not use this at all if it can be done otherwise with Vaadin. Any thoughts?

Nobody did this with Vaadin? Is the javascript even needed to create that flow? I can't tell, paypal documentation looks real messy to me

The javascript stuff starts from:

Setting Up Web Pages To Invoke the Digital Goods Payments Flow

To invoke the digital goods payments flow, follow these steps to add JavaScript to your webpages:

1. Include the following path to the JavaScript file dg.js.

https://www.paypalobjects.com/js/external/dg.js

For best performance, place the path to the JavaScript file just before the closing </body> element in your page.
2. Customize and include the following code after the JavaScript file. Replace "submitBtn" with the ID of your HTML form button.

Is CustomLayout any help in this?

Last updated on Oct, 7th 2011
Mathias Clerc
1 decade ago Oct 04, 2011 12:52am

I don't know if there is some better way, but I used the following code to inject a custom js library in Vaadin :

String script = "try{var fileref=document.createElement('script');";
        script += "fileref.setAttribute(\"type\",\"text/javascript\");";
        script += "fileref.setAttribute(\"src\", \"" + PATH_TO_JS_SCRIPT + "\");";
        script += "document.getElementsByTagName(\"head\")[0].appendChild(fileref);}catch(e){alert(e);}";
        window.executeJavaScript(script);

Just replace PATH_TO_JS_SCRIPT with the path to the .js file and it will inject it in the <head> part of the html.
Note that if you run this script during the application init or window creation time, the script will not be injected for refresh/tab close and reopen/...
I am actually using an override on Application.getWindow to handle that (and quite a lot of other things).

Hope that helps

Henri Sara
1 decade ago Oct 04, 2011 6:54am
Mathias Clerc
1 decade ago Oct 05, 2011 1:59am
Tudor Raneti
1 decade ago Oct 05, 2011 2:46pm
Philippe Lhoste
1 decade ago Oct 06, 2011 8:28am
Tudor Raneti
1 decade ago Oct 06, 2011 3:55pm
Tudor Raneti
1 decade ago Oct 06, 2011 4:59pm
Mathias Clerc
1 decade ago Oct 07, 2011 1:15am
Tudor Raneti
1 decade ago Oct 07, 2011 6:51am
Tudor Raneti
1 decade ago Oct 07, 2011 4:11pm
Philippe Lhoste
1 decade ago Oct 10, 2011 8:43am
Tudor Raneti
1 decade ago Oct 10, 2011 9:26am
Fernando Torterolo
7 years ago Sep 25, 2014 1:59pm
adil benjelloun
5 years ago May 17, 2016 9:41am
Janis Pütz
4 years ago Aug 13, 2017 2:05pm

If you just need to include a js class, you could use the annotation @JavaScript({"pathToFIle.js"}) on a component or the whole application class.