Planned maintenance is scheduled for the week of June 15th - the exact date and time will be announced soon.
See More Details
Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: javascript in portlets
Greetings,
I have four portlets in a liferay page. I include the same javascript file in the header of each of these portlets using the <header-portlet-javascript> tag in the liferay-portlet.xml file. Does this mean that each of these portlets get their own copy of this javascript file?...or is there just one global file for the entire page?
thanks,
Vasanth
I have four portlets in a liferay page. I include the same javascript file in the header of each of these portlets using the <header-portlet-javascript> tag in the liferay-portlet.xml file. Does this mean that each of these portlets get their own copy of this javascript file?...or is there just one global file for the entire page?
thanks,
Vasanth
I think you'll have as JS file as the number of portlet which declares it in the liferay-portlet.xml .
It's better to delegate to a theme the loading of the JS files.
It's better to delegate to a theme the loading of the JS files.
Leo,
I looked at the source for the portal page, and the js file was included only once in the <script> tag. So I guess, it's global to the page. The theme option you suggested looks interesting. I'll try that shortly.
I have another question. Let's say there are two portlets in a page and they have the same names and ids for the DIV elements in them. They both call the same javascript function to update the DIV. Now which DIV will get updated? I think we have to use portlet namespaces to solve this problem. I haven't used them...have you?
Vasanth
I looked at the source for the portal page, and the js file was included only once in the <script> tag. So I guess, it's global to the page. The theme option you suggested looks interesting. I'll try that shortly.
I have another question. Let's say there are two portlets in a page and they have the same names and ids for the DIV elements in them. They both call the same javascript function to update the DIV. Now which DIV will get updated? I think we have to use portlet namespaces to solve this problem. I haven't used them...have you?
Vasanth
Yes,you should use namespaces. You should simply prepend <portlet:namespace/> to your ids and js functions
That makes sense. So if I have two portlets on a page that use a common function (say function myFunc()), the javascript will eventually have two functions like function ads_hgj_myFunc() and tut_hdr_myFunc(), where the garbage in front of the function name in this example is the namespace?
For the IDs, it depends on your portlet.
With a Liferay Struts or MVC portlets, you'll need to use portlet:namespace. But I develop JSF portlet, and I do not need to put the portlet id on my ID attributes. Liferay (or JSF ?) auto-writes the portlet ID.
It's great, but there is a problem with JS code : so I use jQuery selector to find my elements with ID (for example: $('input[id*=foo]')). Because I do not want to import liferay "portlet" taglib in my "xhtml" files.
With a Liferay Struts or MVC portlets, you'll need to use portlet:namespace. But I develop JSF portlet, and I do not need to put the portlet id on my ID attributes. Liferay (or JSF ?) auto-writes the portlet ID.
It's great, but there is a problem with JS code : so I use jQuery selector to find my elements with ID (for example: $('input[id*=foo]')). Because I do not want to import liferay "portlet" taglib in my "xhtml" files.
Community
Company
Feedback