You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Chris Gerken <ch...@mindspring.com> on 2012/07/23 00:10:54 UTC

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: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: Javascript and multiple instances of a portlet on a page

Posted by Woonsan Ko <wo...@yahoo.com>.
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 <ch...@mindspring.com>
> To: jetspeed-user@portals.apache.org
> 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: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: Javascript and multiple instances of a portlet on a page

Posted by Ron McNulty <rm...@clear.net.nz>.
Hi Chris

There is a function available I think as a tag in the portlet tag library. 
It's job in life is to create differently named Javascript variables for 
each portlet instance. It simply adds a portlet instance specific prefix to 
your variable names. Try skimming the JSR 286 specification for more info.

Regards

Ron

----- Original Message ----- 
From: "Chris Gerken" <ch...@mindspring.com>
To: <je...@portals.apache.org>
Sent: Monday, July 23, 2012 10:10 AM
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: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org