Foren

XMLPortletRequest and AJAX with JSR286 Eventing

Blaine Boule, geändert vor 14 Jahren.

XMLPortletRequest and AJAX with JSR286 Eventing

New Member Beiträge: 15 Beitrittsdatum: 02.12.09 Neueste Beiträge
Hello, we are standing up/evaluating Liferay here where I work. (Potential for close to 90k users)

I am on a team that is evaluating the portlet development process and our transition to this technology. We are currently a heavy J2EE shop with Flex and Oracle SOA thrown in the mix.

One thing we are trying to do is couple JSR286 eventing with AJAX. We have eventing working, that was easy, but now we want to have Portlet A post the event via AJAX, this then fires the event to Portlet B's processEvent, which renders the jsp with the event data. This works great without ajax, with a page refresh, but we are placing flex into the portlets and want to avoid the reload of the SWF's.

Using AJAX, when we do the post, the event fires, the render is called on portlet B, but the entire portal response is returned to Portlet A - not ideal. We have been reading about using XMLPortletRequest which allows the portal container to understand that portlet A pushed the event and has its render method called, but in the process portlet B becomes stale and needs updating as well. Looking through SVN, I see that this, XMLPortletRequest, was added to Liferay 5.2 and we are on 5.2.3 but cannot get this to work. Basically we are trying to do what this diagram explains:


Image Src

Do you have any examples that shows this in action?

Also, we noticed in the comments on SVN that the XMLPortletRequest.js should be added to our portlet when we deploy, but this isn't occurring either - we have been manually adding it.

Any help would be great

Blaine
Peter Fox, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

New Member Beiträge: 18 Beitrittsdatum: 09.10.09 Neueste Beiträge
Hi Blaine,

Any improvement on this?!! I'm already tryind to do the same thing and I found some examples on web that maybe suite to the result ..but can not find XMLPortletRequest javascript implementation to add manually to portlet (since liferay seams to not have it)... for what i see if you don't include that js object implementation and with firebug i check that XMLPortletRequest object does not exist...

Can you point me where I can download it to add into my portlet?


"This feature has been added in Portlet Container 2.1. This is available in OpenPortal Portlet Container 2.1, Sun GlassFish Web Space Server 10.0 and Liferay version 5.2 and higher."

but this stament seams to be completely false I'm using 5.2.3, and when liferay deploys the portlet nothing is added to it...

I want to try this:

https://portlet-container.dev.java.net/docs/ClientSideEventing.html

Thanks in advance,

BR
thumbnail
Deepak Gothe, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

Junior Member Beiträge: 44 Beitrittsdatum: 19.05.08 Neueste Beiträge
In Liferay 5.2.3, you need to set portlet.container.impl=sun in portal-ext.properties and restart the webcontainer. After this when you deploy the portlet, you will see XMLPortletRequest.js getting added.
Peter Fox, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

New Member Beiträge: 18 Beitrittsdatum: 09.10.09 Neueste Beiträge
Thanks for your reply Deepak,

(not usual to get some...and on so short time...really appreciate it!!!)

Got to know that, I've found a XmlPortletResquest.js implementation from some other portal and deployed it with the portlets... it works from the example that I've pointed on previous (at least ajax request from AjaxProducerPortlet...it gets a ajax response... but nothing new with this), but it should fire and event and EventConsumerPortlet should re-render ...(but this one , which I was interested is not working......at least for me)

Do you have some pointers on how to perform IPC between portlets using Ajax... I'm trying lots of things last weeks but can not achieve a good method to perform that... i'm sarrting to get my moral down with this..and thinking that best method is to do it "jerk"...

Jerk method:

1- portlet say A...perform Ajax call
2 - portlet A get callBack response.... and with jQuery should be easy to get all portlet's on web page.. (also there's a google code project )
http://code.google.com/p/jquery-portlet , that could be used to achieve this but with css selectores and jQuery it can be done too...
3- update Portlet A callback result on ....some other portlets on page

This actually works...but seems really ugly ..... and I don't like this solution...but seams to be the better I'm founding...

Do you have any better approach to advice to me?

Ok...another issue that I've found...is that consumer / producer portlets are packaged on different wars... a class cast exception is performed when event occours? I guess that if I set portlet.container.impl=sun too this will be solved

Liferay claims IPC 286 compliance but I have to change portlet-container implementation to SUN? Selling smoke?

portlet.container.impl=sun



Thankas once again.

BR peter
thumbnail
Deepak Gothe, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

Junior Member Beiträge: 44 Beitrittsdatum: 19.05.08 Neueste Beiträge
You can try the sample related to Client Side eventing using AJAX . You can check the blog on this topic.
There were some issues related to Client Side Eventing in Liferay 5.2.3 which has since been fixed. You can get the patch. Copy portlet-container.jar and container.jar from the zip to the server classpath(TC_HOME/lib) and restart the web container.

Liferay is JSR286 compliant. The version 5.2.3 has two JSR286 implementations, one internal(which is default) and other sun, which you can specify by setting the property portlet.container.impl=sun in portlet-ext.properties. Both implementations are JSR286 compliant.

Regarding the issue of getting classcast exception when consumer / producer portlets are packaged in different wars, this is because of the way eventing payload is handled. In case of portlet.container.impl=sun, JAXB serialization is used hence no classcastexception is thrown. For that the JVM should be JDK1.6.
Peter Fox, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

New Member Beiträge: 18 Beitrittsdatum: 09.10.09 Neueste Beiträge
Thanks Deepak for your time and clarification...

I want to give it a try...but:

portlet.container.impl

propertie on my current portal.properties does not exist... so this is a hidden propertie? if I add it into my portal-ext.properties it will override de current one that is not shown anywhere?

Those jars on the patch you linked to me ... should I put them on TOMCAT_HOME/lib/ext ??? or TOMCAT_HOME/lib?
Don't understand what you try to mean with TC_HOME/lib .. since I'm not sure what is TC_HOME....

Thanks once more.

kind regards

Peter
Peter Fox, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

New Member Beiträge: 18 Beitrittsdatum: 09.10.09 Neueste Beiträge
Update:

svn info
Path: .
URL: http://svn.liferay.com/repos/public/portal/branches/5.2.x
Repository Root: http://svn.liferay.com/repos/public
Repository UUID: 05bdf26c-840f-0410-9ced-eb539d925f36
Revision: 42261
Node Kind: directory
Schedule: normal
Last Changed Author: michael.hashimoto
Last Changed Rev: 36691
Last Changed Date: 2009-09-01 22:47:05 +0000 (Tue, 01 Sep 2009)



svn update --> no changes done...


propertie dow not exist but if I google for it...i FIND

Portal Properties 5.2.3 - Wiki - Liferay

portlet.container.impl=internal #portlet.container.impl=sun # # Set this property to ...... ldap.attrs.transformer.impl=com.liferay.portal.security.ldap. ...

wHAT i'M MISSING?

Should I have to get trunk ?


thanks
Peter Fox, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

New Member Beiträge: 18 Beitrittsdatum: 09.10.09 Neueste Beiträge
Bummmmm

Portlet section on TRUNK: portlet.properties (http://svn.liferay.com/repos/public/portal/trunk/portal-impl/src/portal.properties)

##
## Portlet
##

#
# Set this property to set the default virtual path for all hot deployed
# portlets. See liferay-portlet-app_5_1_0.dtd and the virtual-path element
# for more information.
#
portlet.virtual.path=

#
# Set this property to true to validate portlet.xml against the portlet
# schema.
#
portlet.xml.validate=true

ON WIKI:

http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Portal%20Properties%205.2.3

Portlet

#
# Set this property for the portlet container implementation to use. The
# default implementation is the internal Liferay implementation and provides
# for the most features and best performance. The Sun implementation
# demonstrates how to plugin a different portlet container implementation.
#
portlet.container.impl=internal
#portlet.container.impl=sun

#
# Set this property to set the default virtual path for all hot deployed
# portlets. See liferay-portlet-app_5_1_0.dtd and the virtual-path element
# for more information.
#
portlet.virtual.path=

#
# Set this property to true to validate portlet.xml against the portlet
# schema.
#
portlet.xml.validate=true



DON't KNOW WHAT TO DO WITH MYSELF!!emoticon

Any help greatly appreciated!! Don't know what I'm missing!

Regards,

Peter
Peter Fox, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

New Member Beiträge: 18 Beitrittsdatum: 09.10.09 Neueste Beiträge
Deepak,

Really fresh your jar files..so I guess you get it working...
Can you please gently provide me further directions...I'm getting lost emoticon

Hope to hear from you soon.

Regards

Peter
Peter Fox, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

New Member Beiträge: 18 Beitrittsdatum: 09.10.09 Neueste Beiträge
Deepak Gothe:
In Liferay 5.2.3, you need to set portlet.container.impl=sun in portal-ext.properties and restart the webcontainer. After this when you deploy the portlet, you will see XMLPortletRequest.js getting added.


I've done this and it works actually... XMLPortletRequest.js getting added..to deployed portlet...

From the sample... the Producer Portlet works as before... It performs ajax call with zip code --> enter java side on Producer portlet (serveResource method and returns the Producer response)... javascript callBack gets java response and renders the Producer response ...and after that calls setEvent...in order to get it portlet B (the consumer) ....

....but....

after that nothing is done....

So only 1 possibilities:

This is not being performed: (since without the extension and with non-ajax form submits and total page rendering event occurs!!)

Portlet Container reads portlet.xml during deployment and recognizes client-side events from the special marker class com.sun.portlet.ClientEvent. While rendering the portlet, it generates a namespaced javascript event queue, <portlet:namespace/>EventQueue, for the generator and populates it with a list of consumers on the page.
When XMLPortletRequest.setEvent is called, it in turn calls setEvent on the generator's event queue. Generator's event queue loops through consumer list and calls <portlet:namespace/>PortletObj.processEvent on each. This is why it is mandatory to implement processEvent function to be able to consume events.

Deepak...did you get it working? Maybe is some problem with my configuration and the jars you provided?

Really need you help!!!

Regards

Peter
thumbnail
Deepak Gothe, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

Junior Member Beiträge: 44 Beitrittsdatum: 19.05.08 Neueste Beiträge
Which browser are you trying this on? Looks like there might be some javascript errors, check the error console.
Have you applied the patch. In Tomcat-home/lib/ext, you might see portlet-container.jar and container.jar. Overwrite those with the ones from the patch. This is applicable for Liferay 5.2.3 released version only.
thumbnail
Deepak Gothe, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

Junior Member Beiträge: 44 Beitrittsdatum: 19.05.08 Neueste Beiträge
Ok.I see why the sample from https://portlet-container.dev.java.net/docs/ClientSideEventing.html did not work for you.Its because of speed-filters. Create a file liferay-plugin-package.properties in WEB-INF. In this file add the following line

speed-filters-enabled=false

and try again.
Peter Fox, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

New Member Beiträge: 18 Beitrittsdatum: 09.10.09 Neueste Beiträge
Deepak Gothe:
Ok.I see why the sample from https://portlet-container.dev.java.net/docs/ClientSideEventing.html did not work for you.Its because of speed-filters. Create a file liferay-plugin-package.properties in WEB-INF. In this file add the following line

speed-filters-enabled=false

and try again.


Hi Deepak,

Can't have any progress on this...

speed-filters-enabled=false on liferay-plugin-package.properties package on war inside WEb-INF dows not change nothing...

I don't have any JS errors (I'm using Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5) and I checked all JS objects with Firebug...

This is what I've done:

1 - Dowloaded https://portlet-container.dev.java.net/public/Download.html#Instructions_to_install_Portlet_

2 - Inside jar file (which is an installer there's a lib folder) I've copy all jar files (less portlet.jar which already exists) into TOMCAT_HOME/lib/ext

3- apply you patch and overwrite the 2 jar files for 5.2.3

4- restart tomcat

5 - On the sample add the iferay-plugin-package.properties with speed-filters-enabled=false

6- mvn clean package on sample... builds a fresh new war ...

7 - deploy it into tomcat... portlet's (ajaxproducer and ajaxconsumer) are registered successfully ...

8 - Add them to a portal page....

9 -- Hit get weather ..on ajaxportlet producer... it works...it get the weather and render it's reponse...and call setEvent....

10 -- Portlet AjaxConsumer (which should be list for the Event...does nothing.... stays on it initial state and not render the maop as it should....)

Don't know what to do... Server side Java from AjaxConsumerPortlet is not being called so i guess the problem is that setEvent part on AjaxProducer javacript part not working correctly (again nop js errors) . . .don't know how to debug this and how to check events on event queue that is mentioned on sample ....

Running out of ideas....


Thanks once more,

BR

Peter
thumbnail
Deepak Gothe, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

Junior Member Beiträge: 44 Beitrittsdatum: 19.05.08 Neueste Beiträge
Undo what you did in steps #1 and #2.
1. You should get the patch from here
2. It contains only two jars files - container.jar and portlet-container.jar and copy them to TOMCAT_HOME/lib/ext (it will overwrite the existing ones).

Continue with your remaining steps..It should work now.

To ensure that you have correctly followed the steps
1. The manifest of portlet-container.jar in TOMCAT_HOME/lib/ext should mention the build number as 900
2. The web.xml of the ClientEventingPortlet.war should not have any entries for Cache Filter, GZIP Filter
Peter Fox, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

New Member Beiträge: 18 Beitrittsdatum: 09.10.09 Neueste Beiträge
hummm got problems...

With steps #1 and #2 undo... and with current web.xml for portlet as follow:

web.xml

<code>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
</code>

I got JS error ... saying that XMLPortletRequest.js not exists


On my portal portal.properties (as I've told on a previous post) ... I don't have ANY

portlet.container.impl=internal
#portlet.container.impl=sun # # Set this property to ......

As is said to exist on wiki: http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Portal%20Properties%205.2.3

You can check that on svn trunk:

http://svn.liferay.com/repos/public/portal/trunk/portal-impl/src/portal.properties

or on http://svn.liferay.com/repos/public/portal/branches/5.2.x (wich I'm using)

That properties does not exist on the portal.properties that is present on SVN and off course not present inside portal-impl.jar file.

Even if I add/set that properties... on portal-ext.properties (TOMCAT_HOME/webapps/ROOT/classes) to:

portlet.container.impl=sun

(I'm defining that propertie since no override occurs since it does not exist!!! on portal.properties .... )


Well... I've tried to put inside war (the XMLPortletRequest.js) and deploy again.... this way I don't get JS error.... but is the same as on all the post before... AjaxProducerPortlet works..... and it sends the event from JS... I can trace it on Firebug.... but AjaxConsumerPortlet... does simply NOTHING!

I guess...that the problem is portlet.container.impl=sun.... no JS is inserted on war at deploy time now (making undo on steps #1 and #2 ---> removing the jars , restart tomcat, re-deploy portlets)


Don't know... seams to me that this can not work on liferay... or SVN is not GOOD since that propertie not exist!!!

WIKI IS NOT AT SYNC WITH SVN... emoticon the previous urls prove that ... or I'm blind!!

Can not sleep anymore with this one!!

Thanks Deepak... if you have some other suggestion...I'll really appreciate.


regards,

Peter
thumbnail
Deepak Gothe, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

Junior Member Beiträge: 44 Beitrittsdatum: 19.05.08 Neueste Beiträge
The property, portlet.container.impl=sun is present only in Liferay Portal 5.2.3 Community Edition release only. You will not find it in the latest trunk. If you want to work with the latest trunk, then you will not be able to use XMLPortletRequest. But if your requirement is Client side Eventing then you can use http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Client-side+Inter-Portlet+Communication
Peter Fox, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

New Member Beiträge: 18 Beitrittsdatum: 09.10.09 Neueste Beiträge
Deepak Gothe:
The property, portlet.container.impl=sun is present only in Liferay Portal 5.2.3 Community Edition release only. You will not find it in the latest trunk. If you want to work with the latest trunk, then you will not be able to use XMLPortletRequest. But if your requirement is Client side Eventing then you can use http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Client-side+Inter-Portlet+Communication



Yes, I've tried actually already Liferay own...Client-side+Inter-Portlet+Communication... but want to try JSR-286 Eventing model to perform actually that... seams to me to be a better approach...

So, I guess I've to download binary distribution...for community 5.2.3 ...I'm correct? I can not use SVN?

Regards,

Peter
thumbnail
Deepak Gothe, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

Junior Member Beiträge: 44 Beitrittsdatum: 19.05.08 Neueste Beiträge
Yes you have to download binary distribution for community 5.2.3. You cannot use SVN.
Trivedi Bodlapati, geändert vor 13 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

New Member Beiträge: 3 Beitrittsdatum: 01.08.10 Neueste Beiträge
Hi Deepak,

I was actually looking into this server side IPC with Ajax based. In normal way, when the portletA publishes the event, liferay is refreshing the page. Could you pls help on how to attack this problem with XMLPortletRequest.js. FYI, I am a new bee on liferay.

Thanks,
Trivedi
Akshat Garg, geändert vor 12 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

New Member Beiträge: 2 Beitrittsdatum: 24.01.12 Neueste Beiträge
Hello Deepak,

Is there any way by which I can do client side eventing using JSR 286 specifications in Liferay6 and above. I want to use Eventing Mechanism of JSR 286 and don't want to have full page refresh in case of Inter Portlet communication. (In Liferay 5.2.3 it is possible by enabling open portal portlet container but same is not working in Liferay 6.0.6)

Hope an early response from your side.
Peter Fox, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

New Member Beiträge: 18 Beitrittsdatum: 09.10.09 Neueste Beiträge
This is what is present on PORTLET session on portal.properties (as you can see portlet.container.impl dows not exist on the session... and on the complete file!! )

##
## Portlet
##

#
# Set this property to set the default virtual path for all hot deployed
# portlets. See liferay-portlet-app_5_1_0.dtd and the virtual-path element
# for more information.
#
portlet.virtual.path=

#
# Set this property to true to validate portlet.xml against the portlet
# schema.
#
portlet.xml.validate=true

##
## Portlet Coordination
##

#
# Set this property to specify how events are distributed. If the value is
# "layout-set", then events will be distributed to all portlets contained in
# a layout set. This will only work correctly if the property
# "layout.default.p_l_reset" is set to false. If the value is "layout", then
# events will be distributed to all portlets that are present in a layout.
#
portlet.event.distribution=layout

#
# Set this property to specify how public render parameters are distributed.
# If the value is "layout-set", then public render parameters will be
# distributed to all portlets contained in a layout set. This will only work
# correctly if the property "layout.default.p_l_reset" is set to false. If
# the value is "layout", then public render parameters will be distributed
# to all portlets that are present in a layout.
#
portlet.public.render.parameter.distribution=layout
Peter Fox, geändert vor 14 Jahren.

RE: XMLPortletRequest and AJAX with JSR286 Eventing

New Member Beiträge: 18 Beitrittsdatum: 09.10.09 Neueste Beiträge
ATTACHED IS THE WAR with AjaxProducerPortlet and AjaxConsumerPortlet (I've added inside of war js/XMLPortletRequest.js)