Is AJAX for inter portlet communication possible?
Asked Answered
F

2

6

I know that you can create portlets that can refresh its content without refreshing the whole portal page by simply using the JSR286 resourceURL tag and doing an AJAX call.

My question is, is it possible to do an AJAX call in Portlet A and somehow target and dynamically update Portlet B instead?

The idea is to avoid the who portal page refresh (re-rendering) when you do inter-portlet communication via actionURL or events.

Fonsie answered 1/3, 2011 at 17:11 Comment(1)
searching for the same...did u find some way?Hasheem
O
1

You may use jQuery trigger() and bind() methods to communicate between portlets. With this approach all communication will happen on clientside (browser) without any server interaction.

The portlet B that listens to the event should do something like:

$(document).bind("myevent", function(event, param) {
     // do your work here
     alert("message recieved with data " + param);
});

The portlet A that fire the event should do the following:

$(document).trigger("myevent", "mydata");
Outbrave answered 3/7, 2012 at 17:28 Comment(0)
G
0

If Portlet B does not need to perform server-side logic, then you could simply use pub/sub on the client and have Portlet B listen to a particular event that Portlet A will publish.

So flow is:

  1. Inital HTML page is sent to the client, with Portlet A and Portlet B on.
  2. Pub/sub system is initialised on client. Maybe use something like amplifyjs.
  3. Portlet B on the client registers for topic called "MyDataUpdated" (or whatever meaningful name you want to give the topic).
  4. Client triggers a serveResource call to Portlet A via XHR.
  5. Portlet A on the server does logic for serveResource call.
  6. Portlet A on the server sends its response back to the client.
  7. Portlet A on the client consumes the serveResource response and publishes the result using the topic "MyDataUpdated".
  8. Portlet B on the client receives a notification of the "MyDataUpdated" event.
  9. Portlet B on the client can refresh itself.

Using pub/sub in this way decouples the portlets from each other. If Portlet A does not exist, Portlet B does not break. If Portlet B does not exist, Portlet A does not break.

And if Portlet C comes along and also is capable of acquiring MyData, this portlet could also start publishing "MyDataUpdated" events, and Portlet B will start to get these events too. It gets the new updates for free!

Garretson answered 9/9, 2011 at 21:44 Comment(1)
Can you please kindly provide some tutorial or tips resource if you have. ThanksEmbus

© 2022 - 2024 — McMap. All rights reserved.