We use them in each portlet, and friendly up the javascript names (make them
unique) using the Portlet ID, this way you can have common javascript names
you reference in your portlets using the portletid.  We had to muck the
JS_PEID to remove the hyphens, as they didn't work well together. 

-----Original Message-----
From: Hampton, Thomas [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 21, 2004 3:07 PM
To: [EMAIL PROTECTED]
Subject: How to correctly Java Script with Jetspeed ?

I'm having problems using Java Script in portlets because I don't know
the correct place to put the function definitions.  Java Script
functions are supposed to be defined in the <HEAD> section to make sure
that the scripts are loaded before they can possibly be called, but the
HTML for portlets don't have <HEAD> tags.

I'm using Jetspeed 1, is this handled differently in Jetspeed 2 ?

I've scanned the discussion forums and found the following suggestions.

1) JavaScript does not need to be in the <HEAD> tag just put it in the
body, that it was just convention that it's put in the <HEAD> tag.
 
This is kind of true, the Java Script documentation says the following: 

        Generally, you should define the functions for a page in the
HEAD portion of a document. That way, all functions 
        are defined before any content is displayed. Otherwise, the user
might perform an action while the page is still loading 
        that triggers an event handler and calls an undefined function,
leading to an error. 

The question is then, what else, besides putting the script definitions
in the HEAD tag, can you do to guarantee that the functions are defined
before content is displayed.  Different browsers process the content
differently.  I have not been having problems with IE but in Mozilla, if
you are quick, it's possible to click a link that triggers some script
that has not yet been processed.

2) Override the JetSpeed template file and put all the JavaScript into
the HEAD tag there.

This would mean that all my script would have to be in the portal layout
pages because that's where the HEAD tags are: 

        templates\jsp\layouts\html\content.jsp
        templates\jsp\layouts\html\default.jsp
        templates\jsp\layouts\html\previous.jsp

And that it would be loaded all the time whether it's needed or not for
any page in the portal.  This is pretty non-elegant solution, especially
if you have a lot of script in your portal, but it would work.

3) It was suggested that other portals have a way to add content
dynamically (maybe I misunderstood this one) into the HEAD tag.


Here's a questions/suggestion from me :

Is it possible in Jetspeed to include the HEAD tags in the portlet's
HTML and have the portlet code (HTML portlet) merge the contents of the
HEAD tags from all portlets on a page together before sending the HTML
to the browser ?  Seems like this would solve the problem.



I would like to hear what everyone else thinks, as I've not yet
discovered a workable solution that I'm happy with.

Thanks,
Tom






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to