cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Share component, where to put JavaScript?

gronfelt
Champ in-the-making
Champ in-the-making
I have an ordinary webapp built with JavaScript, HTML and CSS, it's function is to connect to a LDAP-server and change the users password.

Now I would like to create a Share component out of that app. I've separated the CSS, JS and HTML to different files. Then I created a xml file and named it pwchange.get.desc.xml, renamed the HTML-file to pwchange.get.html.ftl and put them in appropriate directories. I also created a pwchange.get.head.ftl, that points to the CSS-file.

So far, so good. I've reloaded the webscripts and have been able to add my webapp to the share UI. The HTML looks right and the CSS is applied correctly.

But where do I put the JavaScript code? The major functionality of the code is to make a http request to another server and then receive the answer. Should it be in a js-file in the same location as the CSS file, should it be in pwchange.get.js along with the other files or should it simply be put in the html.ftl-file? I've tried all three and the only thing that seems to be working is putting the js-code in the html.ftl-file (which is basically just a html-file in this case), but that doesn't seem like the right way to do it.
5 REPLIES 5

gronfelt
Champ in-the-making
Champ in-the-making
I've got another issue too: If I put the JS code in the html.ftl-file, the JavaScript seems to work, however, the http request returns an empty string (I checked this with Firebug). If I issue the same HTTP request directly in the browsers adress field the return string is the expected. What could be the cause of that?

stevericker
Champ in-the-making
Champ in-the-making
Just curious, did you ever figure this out?  I'm a bit confused about where javascript code should go as well and wanted to piggyback off of anything you might've learned as I try to get up the learning curve!  Thanks very much.

gronfelt
Champ in-the-making
Champ in-the-making
Client-side javascript code is preferably put in tomcat/webapps/share/components/dashlets for instance, if it's a dashlet, and then included in the head.ftl-file.

gronfelt
Champ in-the-making
Champ in-the-making
I'd like to extend my answer above with a question of my own:

Can client-side javascript files be included from a location outside the webapp? At the moment I include them like this:

<@script type="text/javascript" src="${page.url.context}/components/dashlets/jsFile.js"></@script>

Is there a way to put them in the shared classpath so that they're not overwritten at an upgrade, but still are reachable for the client?

mikeh
Star Contributor
Star Contributor
Client-side JavaScript files can be anywhere on the Internet - for example, a "share-extension" folder in webapps/ROOT.

Thanks,
Mike