Hi Chris,

If you want to include the javascript file only once, then you should 
*contribute a head element* for the javascript.
A portlet can contribute any element in the head of the page by using Portlet 
2.0 API (PortletResponse#createElement() and 
PortletResponse#addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, element)).

So, after creating a javascript element with specifying the attributes (such as 
'src' and 'type'), invoke #addProperty() with the specific key 
(MARKUP_HEAD_ELEMENT). Then the element will be rendered in the head area of 
the portal page.
One more thing (Jetspeed-2 specific feature) is that you have to set 'id' 
(case-insensitive) attribute to the same value in order not to include the head 
element more than once.
So, even if multiple elements with the same id are contributed, the portal 
renders it only once because those have the same id.
For more detail, see the portlet 2.0 spec, and see the following JIRA issue for 
the Jetspeed-2 specific feature:
https://issues.apache.org/jira/browse/JS2-949


Regards,

Woonsan


----- Original Message -----
> From: Chris Gerken <[email protected]>
> To: [email protected]
> Cc: 
> Sent: Sunday, July 22, 2012 6:10 PM
> Subject: Javascript and multiple instances of a portlet on a page
> 
> Howdy all,
> 
> I need to implement a portlet application whose rendered HTML contains calls 
> to 
> a javascript function and I need multiple instances of this portlet 
> (configured 
> differently) to appear on the same portal page.
> 
> How would I provide the javascript functions?  Would I include the js files 
> from 
> within the rendered HTML for each of the several portlet instances or is 
> there a 
> way to include those files just once for the entire page?
> 
> Thanks, 
> 
> Chris
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to