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 Church Michael R <MR...@qinetiq.com> on 2006/02/06 16:47:28 UTC

Portlet Instance Identification

Hello All,

I have a portlet which defers its HTML rendering to a JSP file.
This JSP file produces a named division and some associated JavaScript,
eg:

  <div id="fred">   blah blah blah    </div>

  <SCRIPT language="JavaScript"><!--

  function updateContent()
  {
    var newContent = 'some new data content';     // some new text
    changeContent(newContent);
  }

  function changeContent(newContent)
  {
    var p = document.getElementByID('fred');
    p.innerHTML = newContent;

    setTimeout(updateContent, 10000);
  }

  updateContent();

  --></SCRIPT>

The idea is that the content of the named division will be updated
every 10 seconds with some new content (which I am getting from a
remote servlet via the use of XMLHTTPRequest).

My problem is this. If I have two such portlets on the same page,
then I have created two divisions with the same name, and two copies
of each of the JavaScript functions. The name clashes can cause all
sorts of problems within the browser.

Is there any way in which I can generate a unique number in my portlet
that I can then use to generate uniquely named divisions and functions
in the case where I have more than one instance of this portlet on the
portal page?

I suspect some clever use of attributes within the portlet session
could be useful here, but I'm not sure. Maybe all I need to do is set
up an APPLICATION_SCOPE integer attribute in the portlet session, and
simply increment its value by one every time doView() is called? Then
the value of that attribute could be exported to the JSP file and made
use of there?

Any thoughts?

Cheers,
Mike


Mike Church
Software Engineering

QinetiQ
Bldg Lovell Rm 109
Malvern Technology Centre
St. Andrews Road, Malvern
Worcestershire, WR14 3PS
Tel: 
01684 896085 
Email: 
mrchurch@QinetiQ.com 
Web: 
www.QinetiQ.com 
QinetiQ - The Global Defence and Security Experts. 


The Information contained in this E-Mail and any subsequent correspondence
is private and is intended solely for the intended recipient(s).
For those other than the recipient any disclosure, copying, distribution,
or any action taken or omitted to be taken in reliance on such information
is prohibited and may be unlawful.

Emails and other electronic communication with QinetiQ may be monitored.
Calls to QinetiQ may be recorded for quality control,
regulatory and monitoring purposes.

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


Re: Portlet Instance Identification

Posted by Jacek Wiślicki <ja...@gmail.com>.
Wiadomosc od Church Michael R z 2006-02-06 16:47 brzmiala:

> The idea is that the content of the named division will be updated
> every 10 seconds with some new content (which I am getting from a
> remote servlet via the use of XMLHTTPRequest).
> 
> My problem is this. If I have two such portlets on the same page,
> then I have created two divisions with the same name, and two copies
> of each of the JavaScript functions. The name clashes can cause all
> sorts of problems within the browser.
"Write" your JS scripts from the layout decorator, not from the protlets 
themselves.Then it will appear in a page code once and will be available 
to all the fragments.

> Is there any way in which I can generate a unique number in my portlet
> that I can then use to generate uniquely named divisions and functions
> in the case where I have more than one instance of this portlet on the
> portal page?
> 
> I suspect some clever use of attributes within the portlet session
> could be useful here, but I'm not sure. Maybe all I need to do is set
> up an APPLICATION_SCOPE integer attribute in the portlet session, and
> simply increment its value by one every time doView() is called? Then
> the value of that attribute could be exported to the JSP file and made
> use of there?
> 
> Any thoughts?
You should read this thread: 
http://www.nabble.com/Retrieving-a-portlet's-unique-instance-ID..-t970653.html#a2514746

-- 
pozdrawiam,
     Jacek Wislicki

jacek.wislicki@gmail.com
tel.: +48 502 408 444
gg: 2540358
skype: jacek_wislicki

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