Inter-Portlet Communication ========================================================================================= IPC using client side java script - Introduction ========================================================================================= The client-side mechanism to communicate portlets is based on events, uses events instead of direct js calls accross portlets is very important since it's not possible to know at deployment time which other portlets will be available in a given page.By firing/triggering an event one portlet just notifies that something has happened, and then one or more of the other portlets in the page might be listening and act accordingly. API used for doing client side PPC is follows, 1.Liferay.trigger(eventName, data) : Trigger an event in which n number of listners can catch the event and act according to the event. 2.Liferay.bind(eventName, function, [scope]) : Listen in for any arbitrary event (it could be anything the developer decides, or an existing one) Bellow is the snippet for PPC using Javascript based IPC Prerequesite: 1. create two jsp portlet using create.bat/sh of plugin sdk a. create.bat ipctrigger "Triggring Portlet" b. create.bat ipclistener "Listening Portlet" 2. deploy these newly created portlets to the server by running "ant deploy" 3. Add the above portlets in to a Portal Page, "IPC Demo" 4. Make sure that both the portlets are appearing fine. 5. Keep the listening portlet on the right side. ========================================================================================= IPC using client side java script - Example 1 ========================================================================================= Example1: Updating a label inside listener portlet using a link provided in the triggering portlet. snippet-1: insert the below code in to docroot/view.jsp of ipctrigger-portlet.
Update Label Using PPC
Remove Label Using PPC snippet-2: insert the below code in to docroot/view.jsp of ipclistener-portlet.