Liferay - client side communication among portlets - liferay

I have a list of portlet projects in eclipse say like 20 (new maybe coming in future or maybe not).
What I wanna do is:
create a new portlet that will listen to all the button interaction
on all those 20 or so portlets and
display the result(success or failure) using this portlet that I
created just now.
I tried looking into IPC but they all have an example where one portlet is firing an event and more than one is listening but I wanna do something vice versa.
How can we achieve this? Any suggestions?

You are looking for client side IPC. So what you need to do is, you can have multiple events bind with the
Liferay.fire(eventName, data)
Liferay.on(eventName, function, [scope])
Fire events will be fired by the sender portlet, you can have multiple fire events from multiple portlets.
To listen those events you need to have liferay.on, whether in a single portlet or in multiple portlets.
You can put up multiple events in receiver portlet JSP(s) using the below format and sample code
Liferay.on('eventName',function(event) {
// write code to get the veluese that sent by sender portlet
});
Example code as follows in receiver portlet view.jsp
Liferay.on('getUserData',function(event) {
alert('User Name:'+ event.name)
});
For further information you can go through the following links.
http://www.liferaysavvy.com/2014/01/liferay-client-side-inter-portlet.html
https://www.liferay.com/web/meera.success/blog/-/blogs/liferay-client-side-inter-portlet-communication-using-ajax
http://www.liferay.com/community/wiki/-/wiki/Main/Inter-portlet+communication

Related

Using socket.io to send data to a specific view/id

I have a web application using NodeJS, Express, and MongoDB. In my application, I have a view, that can be seen by anyone who accesses the application. That view is rendered with a different image, depending on which a user selects to view (they do not need to be logged in) ie the view is mapView/mapId.
Now, I want something similar to notifications to occur in realtime for those that are on that page. When a specific event happens from an external source, I want to display a popup on the view to which the event belongs to. So the event may only belong to one mapView/mapId and not another mapView with a different ID. All users on the same mapView/mapId should see the notification. Remember, these are general users that do not need to be logged in.
I am researching into Socket.io because I know it is for making realtime applications. But I am wondering if this is even the right way to go. How will I send data to the correct mapView/mapId?
Check out what your server can do with rooms
The idea is that each of your connections, from a particular view, is joined to a room. Then you use socket.io from the server to send a message only to that room. And only those sockets will get the message.

When to implement a CDI Event?

When a user clicks a button on JSF, a managed bean receives the input value from front end. To process the request and respond, when should or shouldn't I implement a CDI event? For instance, to print back "Hello World" to html page after a user clicks a button on a front end JSF page, I can implement a CDI Event using event-observer model, or I can do the same thing in many other ways.
My question is, what are appropriate scenarios to implement a request-process operation as a CDI event? Thanks.
Usually you want to use events when a request from user will affect multiple parts of application. Let's say user changed some settings it his profile and they are multiple components affected by this change so you can fire up an single event and all these components will be able to handle the configuration change.
Another argument for using events is to decouple your components so there are less dependencies in your application.
So for your example, events are probably overkill for such simple operation as printing Hello world.

Liferay: How can a portlet automatically poll for updates so multiple instances are synchronized without refresh?

I'm looking to modify one of my existing portlets which is used concurrently by many users to be able to automatically poll for updates and pull down the latest data in that portlet. That way users don't have to refresh the page to see the new data. In otherwords its automatically checking for new data every 10 seconds and refreshing the data.
Almost like a chat client but its pulling down a JSON object every 10 seconds asynchronously.
No problem. On the browser side, query <portlet:resourceURL/> - this goes to the resource-serving phase of your portlet. From there you can deliver any content type you want (kind of like a servlet)
On the server side, you'll need to query for updated data from all the different users, but that's something independent of the portlet spec and rather considered business logic.

XMPP component presence

I have just discovered how awesome XMPP is and I am experimenting with developing multiplayer games as XMPP components (XEP-0114).
However, I am having trouble with indicating presence for the component. Is it true, that the component will need to respond to <presence> stanzas itself?
Sure it can do that, but not if it is down for maintenance. Also, who does the component notify when it is back up? It could of course register all interested users in a database, but if it is down for five minutes, then that list surely will have changed. Users that were not previously interested will be now, and users who were interested won't be any more.
Also, if it crashes (could happen), it cannot send out 'unavailable' presence indications.
Can't this work somehow be offloaded to the server?
When your component receives <presence type='probe'/>, it should reply with your component's current presence.
When your component receives <presence type='subscribe'/>, it should save the from address in a some sort of storage mechanism, then reply with <presence type='subscribed'/>.
When your component comes online, it should send presence to each of the subscribers saved in step 2.
Always make sure to put both a to address and a from address on all stanzas sent by your component. If you are used to writing clients, you're likely to forget that in step 3.

JSF+AJAX push : realtime chat / notification system

I'm trying to add some features to my webapp, something like a "live user-to-user" chat (like Facebook's one) and a realtime notifications system.
Let's consider this scenario :
We've got two users, A and B.
A sends a message to B.
If the chat window between B and A is opened on B's browser, we update it, showing the new message on B's browser.
If the windows's not opened, we need to show a notification or something on B's browser.
So, having a PrimeFaces Dialog as the chat window and a PrimeFaces NotificationBar to show notifications, how can I do that?
I can't use PrimeFaces' push as they don't work with Glassfish.
I've found out about ICEPush, that seems to be a nice way to do this, but the thing about "Rendering groups" stopped me from trying it.
How can I update just a SINGLE client if ICEPush talks about groups?
Should I create a new group for each client?
Something like :
B has a "BwithA" group that is updated when A sends a message to B and the chat is opened, and a "notificationsB" group that is updated when the chat windows is closed?
I can't find out how to do that because, even using groups this way, is A that has to tell B that he needs to update, and A doesn't know if B has to update the dialog or the notificationBar !
I hope that the question is clear, because it's not easy to explain it|
Thanks in advance :)
I don't know how a professional Java programmer would solve your problem, but when I wanted to create a chat, I used standard Primefaces Remote Command component and call-back parameters to create chat and send new messages to user's from the server.
There is a p:remoteCommand component on web-page. The purpose of the component is to get the latest messages from a particular user when action listener is invoked. New messages are passed from the server to javascript function (handler of oncomplete event of the component) via "call-back parameters". The function then checks if there are any messages and appends them to the chat box.
For more information, see How to create JSF chat with AJAX
UPD: the solution above is outdated. Now I would use JAX-RS web-services or web sockets to implement chat. There is also a commercial solutions for real-time data streaming: PubNub, Pusher, etc.

Resources