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 Roberto Rossi <ro...@cone.it> on 2010/09/27 10:03:49 UTC

Re: How to use JQuery ajax in jetspeed

I don't know if there are guides about integrating jQuery (and AJAX in
general) in Jetspeed2 but some months ago, reading messages in this and
the Jetspeed Developers mailing lists , I found a way to do this in the
doView portlet method.

First of all you have to enable the portlet-pipeline in the avalaible
Jetspeed pipelines.
Usually you can do this modifying the pipelines.xml file, uncomment, if
necessary, these lines:

<bean id="portlet-pipeline"
        class="org.apache.jetspeed.pipeline.JetspeedPipeline"
        init-method="initialize"
  >
   <constructor-arg>
       <value>PortletPipeline</value>
   </constructor-arg>
   <constructor-arg>
    <list>
        <ref bean="portalURLValve"/>
        <ref bean="capabilityValve"/>
        <ref bean="securityValve"/>
        <ref bean="localizationValve"/>

        <ref bean="profilerValve"/>
        <ref bean="containerValve"/>
        <ref bean="portletValveTitleInHeader"/>
    </list>
    </constructor-arg>
  </bean>

and

            <entry key='/portlet'>
                <value>portlet-pipeline</value>
            </entry>

Maybe there can differences between my lines and yours. 
I'm currenty using Jetspeed 2.1.3 implementation.

Second you should pass some special parameters to your request to let
Jetspeed communicate only with your "ajax" portlet.
This is an example of a jQuery ajax request that can receive a JSON
response:

                $.ajax({
		    url: '<yourjetspeedappname>/portlet/<yourpage.psml>',
		    type: 'GET',
		    dataType: 'json',
		    data: {"entity": '<yourportletentityname>'},
		    // 1 minute wait
		    timeout: 60000,
		    error: function() {
		        alert('errors');
		    },
		    success: function(json) {
		        alert(json.message);
		    }
		});

You should change <yourjetspeedappname> , <yourpage.psml> and
<yourportletentityname> accordingly with your Jetspeed installation and
page and portlet infos.
You can also use POST instead of GET.
Then in your portlet you should create a JSONObject response like this:

...
JSONObject jsonObject = new JSONObject();
jsonObject.put("type", "success");
jsonObject.put("message", "that's OK");
context.put("jsonObject", jsonObject);
...

the Velocity file (for me: ajax.vm), the view file for this ajax
portlet, contains only this code:

$!jsonObject 

If all the steps are ok you should receive the portlet json message in a
javascript alert in your html code.

I hope this can help!

ROb