<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>javascript in portlets</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=10998775" />
  <subtitle>javascript in portlets</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=10998775</id>
  <updated>2026-05-28T19:07:25Z</updated>
  <dc:date>2026-05-28T19:07:25Z</dc:date>
  <entry>
    <title>RE: javascript in portlets</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=10999716" />
    <author>
      <name>Leo Pratlong</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=10999716</id>
    <updated>2011-10-05T19:34:11Z</updated>
    <published>2011-10-05T19:34:11Z</published>
    <summary type="html">For the IDs, it depends on your portlet.&lt;br /&gt;With a Liferay Struts or MVC portlets, you&amp;#39;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.&lt;br /&gt;It&amp;#39;s great, but there is a problem with JS code : so I use jQuery selector to find my elements with ID (for example: $(&amp;#39;input[id*=foo]&amp;#39;)). Because I do not want to import liferay &amp;#34;portlet&amp;#34; taglib in my &amp;#34;xhtml&amp;#34; files.</summary>
    <dc:creator>Leo Pratlong</dc:creator>
    <dc:date>2011-10-05T19:34:11Z</dc:date>
  </entry>
  <entry>
    <title>RE: javascript in portlets</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=11000455" />
    <author>
      <name>Vasanth Jayabalan</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=11000455</id>
    <updated>2011-10-05T17:58:45Z</updated>
    <published>2011-10-05T17:58:45Z</published>
    <summary type="html">That makes sense. So if I have two portlets on a page that use a common function (say function &lt;em&gt;&lt;strong&gt;myFunc()&lt;/strong&gt;&lt;/em&gt;), the javascript will eventually have two functions like function &lt;em&gt;&lt;strong&gt;ads_hgj_myFunc()&lt;/strong&gt;&lt;/em&gt; and &lt;em&gt;&lt;strong&gt;tut_hdr_myFunc()&lt;/strong&gt;&lt;/em&gt;, where the garbage in front of the function name in this example is the namespace?</summary>
    <dc:creator>Vasanth Jayabalan</dc:creator>
    <dc:date>2011-10-05T17:58:45Z</dc:date>
  </entry>
  <entry>
    <title>RE: javascript in portlets</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=11000276" />
    <author>
      <name>Jelmer Kuperus</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=11000276</id>
    <updated>2011-10-05T17:24:31Z</updated>
    <published>2011-10-05T17:24:31Z</published>
    <summary type="html">Yes,you should use namespaces. You should simply prepend &amp;lt;portlet:namespace/&amp;gt; to your ids and js functions</summary>
    <dc:creator>Jelmer Kuperus</dc:creator>
    <dc:date>2011-10-05T17:24:31Z</dc:date>
  </entry>
  <entry>
    <title>RE: javascript in portlets</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=10999189" />
    <author>
      <name>Vasanth Jayabalan</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=10999189</id>
    <updated>2011-10-05T17:11:37Z</updated>
    <published>2011-10-05T17:11:37Z</published>
    <summary type="html">Leo,&lt;br /&gt;&lt;br /&gt;I looked at the source for the portal page, and the js file was included only once in the &amp;lt;script&amp;gt; tag. So I guess, it&amp;#39;s global to the page. The theme option you suggested looks interesting. I&amp;#39;ll try that shortly. &lt;br /&gt;&lt;br /&gt;I have another question. Let&amp;#39;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&amp;#39;t used them...have you?&lt;br /&gt;&lt;br /&gt;Vasanth</summary>
    <dc:creator>Vasanth Jayabalan</dc:creator>
    <dc:date>2011-10-05T17:11:37Z</dc:date>
  </entry>
  <entry>
    <title>RE: javascript in portlets</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=10999058" />
    <author>
      <name>Leo Pratlong</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=10999058</id>
    <updated>2011-10-05T16:51:24Z</updated>
    <published>2011-10-05T16:51:24Z</published>
    <summary type="html">I think you&amp;#39;ll have as JS file as the number of portlet which declares it in the liferay-portlet.xml .&lt;br /&gt;&lt;br /&gt;It&amp;#39;s better to delegate to a theme the loading of the JS files.</summary>
    <dc:creator>Leo Pratlong</dc:creator>
    <dc:date>2011-10-05T16:51:24Z</dc:date>
  </entry>
  <entry>
    <title>javascript in portlets</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=10998774" />
    <author>
      <name>Vasanth Jayabalan</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=10998774</id>
    <updated>2011-10-05T16:04:44Z</updated>
    <published>2011-10-05T16:04:44Z</published>
    <summary type="html">Greetings,&lt;br /&gt;&lt;br /&gt;I have four portlets in a liferay page. I include the same javascript file in the header of each of these portlets using the &amp;lt;header-portlet-javascript&amp;gt; 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?&lt;br /&gt;&lt;br /&gt;thanks,&lt;br /&gt;Vasanth</summary>
    <dc:creator>Vasanth Jayabalan</dc:creator>
    <dc:date>2011-10-05T16:04:44Z</dc:date>
  </entry>
</feed>
