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 Jan Kowalik <ko...@gmail.com> on 2009/06/17 11:27:27 UTC

AJAX and portlet

Hi,

I have deployed one sample ajax portlet which contains also servlet
responding to asynchronous calls.
It works fine but when jetspeed logs out user cause of inactivity time
out and I have page with ajax portlet displayed I can still work with
it and make asynchronous calls to servlet.
How to check if user session is still active in jetspeed, where to do
it in javascript making calls to servlet or in servlet itself.

Many thanks for any help.


Regards

--
Jan

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


Re: AJAX and portlet

Posted by Roberto Rossi <ro...@cone.it>.
        "Once you have the window id, call:
        
        http://localhost:8080/jetspeed/portlet/?entity=dp-12
        
        Jetspeed will use the usual security constraints to protect
        the  
        portlet, including page, portlet and portlet-window security
        checks  
        automatically for you"
        

Is there a way to force the psml page or the portlet entity to give back
a specific content-type instead of "text/html"?
In this way a portlet could return data like pdf pages, svg xml, ... 

Cone consulting 
Business in rete
Via Sandro Totti 7A - 60131 Ancona
Tel 071 9931 269
Fax 071 9931 270
eMail roberto.rossi@cone.it
Web www.cone.it


Re: AJAX and portlet

Posted by David Sean Taylor <d....@onehippo.com>.
On Jun 18, 2009, at 11:48 AM, Rob Bradley wrote:

>
>
> Roberto Rossi-3 wrote:
>>
>> I think that you can implement a similar functionality using the  
>> first
>> approach suggested to Jan, but that I still haven't try it.
>> Use this url:
>>
>>
>> http://<host:port>/<jetspeed>/portlet/page.psml? 
>> entity=<portletentityid>
>>
>> where page.psml is your psml page (with your portlet) and entity is  
>> your
>> portlet entity id, passing it your parameters (or no one if this is  
>> the
>> default action of the portlet).
>> The http response should contain the new html generated markup, then
>> using a Javascript callback you can replace the portlet content using
>> this new html markup.
>>
>> Maybe, in the next future, we should implement something similar.
>> I'll post my solution.
>>
> Thanks for the quick reply and your suggestion Roberto. I have to  
> admit I
> did try that before replying to this thread as I read your earlier  
> response,
> however I couldn't get it working (it just gave me the entire page  
> instead
> of markup for an individual portlet).
>
> However I could be misinterpreting what you mean by  
> <portletentityid>. I was
> using the fragment ID from the PSML file, should this be something
> different, if so how do I obtain <portletentityid>?
>


The window (entity id) is available for you in the portlet request  
(2.0 spec):

http://www.bluesunrise.com/portlet-api/javax/portlet/PortletRequest.html#getWindowID()

Or, for a more complete solution, say if you need all window ids on a  
page, you can retrieve the PSML for any page from a call like this one  
for the default page (documentation for all Ajax API calls: http://portals.apache.org/jetspeed-2/devguide/guide-ajax-api.html) 
:

http://localhost:8080/jetspeed/ajaxapi

or for another page:

http://localhost:8080/jetspeed/ajaxapi/rss.psml

Your Javascript can then parse for the required entity (or window id).  
Or if you know the window id beforehand, you don't need to make this  
initial call.
The entity id (or window id) is available from this call:

Once you have the window id, call:

http://localhost:8080/jetspeed/portlet/?entity=dp-12

Jetspeed will use the usual security constraints to protect the  
portlet, including page, portlet and portlet-window security checks  
automatically for you



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


Re: AJAX and portlet

Posted by Jan Kowalik <ko...@gmail.com>.
Hello again :)

Just one more question.
If I use

++++++++++++++++++++
$.get("http://localhost:8080/cranfieldPortal/portlet/userHome.psml?entity=P-121f50c6235-10004",
null,
            function(data){
                alert("Data Loaded: " + data);

            }
        );
++++++++++++++++++++

I recieve in data object the portlet html fragment.
How can I extract from it a content of  specific tag ?

It did not work when I tried this:
     data.getElementById("<portlet:namespace/>tagId")



Regards.

Jan

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


Re: AJAX and portlet

Posted by Jan Kowalik <ko...@gmail.com>.
Hi ROb

It works perfectly now, many thanks. JQuery is what I am looking for.
You made my day.

cheers

--
Jan

> I used JQuery for other purposes and I think it's a very powerful
> framework, full of plugins and community rich.
> These are some starting points:
> - http://docs.jquery.com/Ajax
> - http://www.ibm.com/developerworks/library/x-ajaxjquery.html
>
> Good AJAX programming!
>
> ROb
>

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


Re: AJAX and portlet

Posted by Roberto Rossi <ro...@cone.it>.
I'm not an AJAX developer but I think that you should select a more
powerful Ajax and Javascript framework, instead of coding all the xml
and javascript stuff by yourself.

I used JQuery for other purposes and I think it's a very powerful
framework, full of plugins and community rich.
These are some starting points:
- http://docs.jquery.com/Ajax
- http://www.ibm.com/developerworks/library/x-ajaxjquery.html 

Good AJAX programming!

ROb

Re: AJAX and portlet

Posted by Jan Kowalik <ko...@gmail.com>.
Hi all

Thanks for all your replies.
I tried to implement refreshing but as I am a beginner on javascript
and AJAX I was not successful.
I will appreciate if any of you have a look on my code and point what is wrong:



============================================================

<script type="text/javascript" language="JavaScript">
var xhr_refresh;
var READY_STATE_UNITIALIZED=0;
var READY_STATE_LOADING=1;
var READY_STATE_LOADED=2;
var READY_STATE_INTERACTIVE=3;
var READY_STATE_COMPLETE=4;
var HTTP_OK = 200;


function getXMLHttpRequest()
{
  var xhr = null;

  if (window.XMLHttpRequest) {
    // Mozilla/Safari
    xhr = new XMLHttpRequest();
  }else if ( typeof ActiveXObject != "undefined" ){
    // IE
    xhr = new ActiveXObject("MicroSoft.XMLHTTP");
  }
  return xhr;
}

function refresh()
{
    var portletId = "P-121f50c6235-10004";
    var page = "userHome.psml";
    var url = "http://localhost:8080/cranfieldPortal/portlet/"+page;
    event_refresh(url, portletId);
}

function doCounter(){
    setInterval("refresh()", 10000);
}

function event_refresh(url, portletId)
{
  xhr_refresh = getXMLHttpRequest();
  xhr_refresh.onreadystatechange = callback_refresh(portletId);
  xhr_refresh.open("GET", url, true);

  xhr_refresh.send( "entity="+portletId );

}

function callback_refresh(portletId)
{
  // Handle results if the ready state is complete
  if (xhr_refresh.readyState == READY_STATE_COMPLETE)
  {
    if (xhr_refresh.status == HTTP_OK){

     document.getElementById(portletId).innerHTML = xhr_refresh.responseXML;
    }

  }

}
</script>


### content of my jsp for portlet view mode ####

<script type="text/javascript">
  window.onload = function() {
      doCounter();
  };
</script>

============================================================


Is it correct if I do :

 document.getElementById(portletId).innerHTML = xhr_refresh.responseXML;

to replace portlet content ?


Thanks in advance for your help



Best Regards

Jan

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


Re: AJAX and portlet

Posted by Rob Bradley <ro...@visionsolutions.com>.

Roberto Rossi-3 wrote:
> 
> Are you sure you used the
> http://<website>/<jetspeedapp>/portlet/rss.psml?entity=rss and not
> http://<website>/<jetspeedapp>/portal/rss.psml?entity=rss ?
> "portlet" instead of "portal"?
> 
Thanks Roberto, you're correct, embarrassingly a miss-read on my part and I
was using portlet instead of portal as you guessed. It works great and
should allow me to accomplish exactly what I'm looking for.

Thanks to David too, more good information, all your replies have been a
great help so far.
-- 
View this message in context: http://www.nabble.com/AJAX-and-portlet-tp24070003p24107272.html
Sent from the Jetspeed - User mailing list archive at Nabble.com.


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


Re: AJAX and portlet

Posted by Roberto Rossi <ro...@cone.it>.
I used this psml file:

<?xml version="1.0" encoding="UTF-8"?>
 <page>
  <defaults
     skin="orange"
     layout-decorator="decorator"
     portlet-decorator="clear"
  />
  <title>RSS Page</title>
<fragment id="rsspage" type="layout"
name="jetspeed-layouts::VelocityOneColumn">
    <fragment id="rss" type="portlet"
name="MTF::RSSVisualizationPortlet" >
        <property layout="OneColumn" name="row" value="0"/>
	<preference name="ViewPage" readOnly="false">
	 <value>/WEB-INF/templates/instance/rss.vm</value>
          </preference>
    </fragment>
    <fragment id="rss2" type="portlet"
name="MTF::RSSVisualizationPortlet" >
        <property layout="OneColumn" name="row" value="1"/>
		<preference name="ViewPage" readOnly="false">
	       <value>/WEB-INF/templates/instance/rss2.vm</value>
	    </preference>
    </fragment>
</fragment>
</page>

Calling this psml file using this url:
http://<website>/<jetspeedapp>/portlet/rss.psml?entity=rss where rss is
the fragment id of the "MTF::RSSVisualizationPortlet" portlet I receive
this html markup:

<?xml version='1.0' encoding='UTF-8'?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	 xmlns:dc="http://purl.org/dc/elements/1.1/"
	 xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/"
	 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	 version="2.0">

	 <channel>
	 	<title>Punto Informatico</title>
	 	<link>http://punto-informatico.it</link>
	 	<description>Il quotidiano di Internet dal 1996</description>
	 	<language>it-IT</language>

	 	<pubDate>Sat, 16 May 2009 10:08:00 GMT</pubDate>
	 	<lastBuildDate>Sat, 16 May 2009 10:08:00 GMT</lastBuildDate>
	 	<ttl>30</ttl>
	 	<image>
	 		<title>Punto Informatico</title>
	 		<url>http://punto-informatico.it/_box/dati/bottoni/btp3.gif</url>

	 		<link>http://punto-informatico.it</link>
	 		<description>Il quotidiano di Internet dal 1996</description>
	 	</image>
	 	<item>
	 		<title>Microsoft mostra (in parte) Zune HD</title>

<link>http://feeds.punto-informatico.it/c/32288/f/438866/s/430c3ef/l/0Lpunto0Einformatico0Bit0C26237870CPI0CBrevi0Cmicrosoft0Emostra0Ein0Eparte0Ezune0Ehd0Baspx/story01.htm</link>
	 		<description>BigM conferma le voci circolate all'inizio del mese
scorso e svela alcuni dati relativi alla sua creatura in cui, nonostante
tutto, crede ancora&lt;img width='1' height='1'
src='http://feeds.punto-informatico.it/c/32288/f/438866/s/430c3ef/mf.gif' border='0'/&gt;&lt;br/&gt;&lt;br/&gt;&lt;a href="http://da.feedsportal.com/r/39771513444/u/159/f/438866/c/32288/s/70304751/a2.htm"&gt;&lt;img src="http://da.feedsportal.com/r/39771513444/u/159/f/438866/c/32288/s/70304751/a2.img" border="0"/&gt;&lt;/a&gt;</description>

	 		<pubDate>Fri, 15 May 2009 12:25:05 GMT</pubDate>
	 		<guid
isPermaLink="false">http://punto-informatico.it/2623787/PI/Brevi/microsoft-mostra-in-parte-zune-hd.aspx</guid>
	 	</item>
                </channel>
</rss>

Which is an rss generated by the porlet using the rss.vm file.
Only the first portlet fragment is given back but not the entire page.
Are you sure you used the
http://<website>/<jetspeedapp>/portlet/rss.psml?entity=rss and not
http://<website>/<jetspeedapp>/portal/rss.psml?entity=rss ?
"portlet" instead of "portal"?


Cone consulting 
Business in rete
Via Sandro Totti 7A - 60131 Ancona
Tel 071 9931 269
Fax 071 9931 270
eMail roberto.rossi@cone.it
Web www.cone.it


Re: AJAX and portlet

Posted by Rob Bradley <ro...@visionsolutions.com>.

Roberto Rossi-3 wrote:
> 
> I think that you can implement a similar functionality using the first
> approach suggested to Jan, but that I still haven't try it.
> Use this url:
> 
> 
> http://<host:port>/<jetspeed>/portlet/page.psml?entity=<portletentityid>
> 
> where page.psml is your psml page (with your portlet) and entity is your
> portlet entity id, passing it your parameters (or no one if this is the
> default action of the portlet).
> The http response should contain the new html generated markup, then
> using a Javascript callback you can replace the portlet content using
> this new html markup.
> 
> Maybe, in the next future, we should implement something similar.
> I'll post my solution.
> 
Thanks for the quick reply and your suggestion Roberto. I have to admit I
did try that before replying to this thread as I read your earlier response,
however I couldn't get it working (it just gave me the entire page instead
of markup for an individual portlet).

However I could be misinterpreting what you mean by <portletentityid>. I was
using the fragment ID from the PSML file, should this be something
different, if so how do I obtain <portletentityid>?

Thanks again,
Rob
-- 
View this message in context: http://www.nabble.com/AJAX-and-portlet-tp24070003p24096570.html
Sent from the Jetspeed - User mailing list archive at Nabble.com.


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


Re: AJAX and portlet

Posted by Roberto Rossi <ro...@cone.it>.
        Basically it had a render_portlet URL which could force an
        individual
        portlet to re-render it's information on a screen without doing
        a full F5
        style page refresh. Does Jetspeed have anything similar?
        

I think that you can implement a similar functionality using the first
approach suggested to Jan, but that I still haven't try it.
Use this url:


http://<host:port>/<jetspeed>/portlet/page.psml?entity=<portletentityid>

where page.psml is your psml page (with your portlet) and entity is your
portlet entity id, passing it your parameters (or no one if this is the
default action of the portlet).
The http response should contain the new html generated markup, then
using a Javascript callback you can replace the portlet content using
this new html markup.

Maybe, in the next future, we should implement something similar.
I'll post my solution.

Re: AJAX and portlet

Posted by Rob Bradley <ro...@visionsolutions.com>.

Roberto Rossi-3 wrote:
> 
>         BTW .. If it is uneasy to use ajax and servlets with portlets in
>         jetspeed2, can you point me the way how to periodically refresh
>         portlet content to catch changes in database for an instance
> 
> 
> You can use:
> - AJAX
> - http page refresh meta tag (but this cause a whole page refresh)
> - a flash component that fetches periodically xml data from another
> source
> 
I'm currently looking into virtually the same as this but with no luck. What
I want to do is refresh an individual Jetspeed page fragment (portlet) on an
interval. I was able to do this in Liferay by some fairly simple jQuery but
I don't see to be able to achieve the same results in Jetspeed.

I have searched and found a number of posts on these forums about Individual
Portlet Refresh but most of them are over 3 years old and didn't really get
any useful answers at the time (or at least nothing I could understand).

This is causing me quite a headache in our Liferay to Jetspeed portlet
migration.

If it helps, the code I used in Liferay was:

var url = "/c/portal/render_portlet?p_l_id=" + themeDisplay.getPlid() +
"&p_p_id=<portlet:namespace/>&p_p_action=0&p_p_state=normal&p_p_mode=view";
jQuery("#p_p_id<portlet:namespace/>").load(url);

Basically it had a render_portlet URL which could force an individual
portlet to re-render it's information on a screen without doing a full F5
style page refresh. Does Jetspeed have anything similar?

Thanks,
Rob
-- 
View this message in context: http://www.nabble.com/AJAX-and-portlet-tp24070003p24094243.html
Sent from the Jetspeed - User mailing list archive at Nabble.com.


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