How to call external JS file (path set)

1492485, modified 17 Years ago. New Member Posts: 7 Join Date: 10/27/08 Recent Posts
Hi ,

I wanted to add external JS file to the portlet. How can I set the path?

Thanks,
Arunyka
thumbnail
346576, modified 17 Years ago. Liferay Master Posts: 724 Join Date: 12/19/07 Recent Posts
HI,

you can create that file inside ext-web/html/js

and you can set that path inside your jsp file like this:

<script src="/html/js/testing.js" type="text/javascript"></script>

HTH
thumbnail
32991, modified 17 Years ago. Regular Member Posts: 123 Join Date: 9/12/06 Recent Posts
You can also add an entry in the liferay-portal.xml file.

<header-portlet-javascript>/js/testing.js</header-portlet-javascript>

This mechanism will add the reference to the javascript file once even if there were multiple instances of the portlet on the page.
thumbnail
346576, modified 17 Years ago. Liferay Master Posts: 724 Join Date: 12/19/07 Recent Posts
Hi albert,

that way also we can include the js file. but if i want to include many js files, how to do?

can i include like this?

<header-portlet-javascript>/js/appointment/testing1.js</header-portlet-javascript>
<header-portlet-javascript>/js/appointment/testing2.js</header-portlet-javascript>
<header-portlet-javascript>/js/appointment/testing3.js</header-portlet-javascript>

.......etc

Thanks in advance
thumbnail
32991, modified 17 Years ago. Regular Member Posts: 123 Join Date: 9/12/06 Recent Posts
Yes you can. I am using a tree library from webfx. I also created my own javascript that I included after I included the webfx javascript code.

So you can have multiple header-portlet-javascript elements in your liferay-portlet.xml file.

Example:

<header-portlet-javascript>/js/webfx/webfx.js</header-portlet-javascript>
<header-portlet-javascript>/js/scripts.js</header-portlet-javascript>
thumbnail
Mani kandan, modified 15 Years ago. Expert Posts: 492 Join Date: 9/15/10 Recent Posts
Hi,
Is it necessary to include "<instanceable>true</instanceable>" in liferay-portlet.xml file?
In my portlet class if i remove "<instanceable>true</instanceable>" it seems not working, if it placed then it is working
Then, if i make changes in my js file Liferay tomcat forced me to restart the sever.
What's wrong?

In my liferay-portlet.xml file,
<instanceable>true</instanceable>
<header-portlet-javascript>/html/portlet/book/author/main.js</header-portlet-javascript>
thumbnail
Mani kandan, modified 14 Years ago. Expert Posts: 492 Join Date: 9/15/10 Recent Posts
Still no help from Liferay Team?emoticon
thumbnail
Thiago Leão Moreira, modified 14 Years ago. Liferay Legend Posts: 1449 Join Date: 10/10/07 Recent Posts
Hey Mani,

The <instanceable> tag does not have any influence in the javascript rendering.
thumbnail
Mani kandan, modified 14 Years ago. Expert Posts: 492 Join Date: 9/15/10 Recent Posts
Hi Thiago,
I have created one portlet in liferay-portal-6.0.6\tomcat-6.0.29\webapps\ROOT\html\portlet\book\view.jsp
And my js file is in liferay-portal-6.0.6\tomcat-6.0.29\webapps\ROOT\html\portlet\book\js\main.js
Then my liferay-portlet.xml file,
<portlet>
<portlet-name>book</portlet-name>
<instanceable>true</instanceable>
<header-portlet-javascript>/html/portlet/book/js/main.js</header-portlet-javascript>
</portlet>
If I remove <instanceable>true</instanceable> my js file is not rendering if I call from jsp file.
If I include <instanceable>true</instanceable> my js file is rendering but if I make any changes in js file it is affecting after I restart the tomcat server.
I don't why its happening?emoticon
thumbnail
Thiago Leão Moreira, modified 14 Years ago. Liferay Legend Posts: 1449 Join Date: 10/10/07 Recent Posts
You are developing your portlet in the wrong way, That's why the configurations are not working as expected. You SHOULDN'T change anything on liferay-portal-6.0.6\tomcat-6.0.29\webapps\ROOT.
This documentation teach you how to develop portlet right Portlet developoment