Skip to main content

Inter-portlet communication in liferay

In this article we will discuss about the Client-side Inter-Portlet Communication......


The JSR-286 (Portlet 2.0) specification gives a mechanism for inter-portlet communication (IPC).
it is mainly started and supported in Liferay since version 5.1.Though there is no perticular solution that fits all the requirments, so Liferay gives an additional method based on JavaScript to perform client side communication.

The client-side mechanism communicates portlets on events.

An event-based model allows one portlet to provide a notification that something of significance has happened, without establishing any kind of hard dependency. Other portlets on the same page that are interested/configured in that event and have registered listeners are then able to act accordingly.

The API is very simple and is mainly based on two methods....

 Liferay.trigger(eventName, data)
 Liferay.bind(eventName, function, [scope])

The above methods have been deprecated in Liferay 6 and replaced with...

 Liferay.fire(eventName, data)
 Liferay.on(eventName, function, [scope])


The bind method works like below...

 Liferay.bind(
   'nameOfEvent', 
   function(event, data){
     // Your javascript
     // data contains data.plid and data.portletId
   }
 );

The triggering of events are like below....

jQuery(
    function () {
      jQuery('a.someHtmlIdentifier').click(
        function(event) {
          var userId = jQuery(this).next().val();
         
          Liferay.trigger('nameOfEvent', {Key: Value});
          return false;
        }
      )
    }
 );

so the bind method for the above event is like this........



 Liferay.bind(
   'nameOfEvent',
   function(event, data) {
     var userVar = data.Key;
     jQuery('.article-results').html('');
     if (userId) {
       jQuery.ajax(
         {
           url: '/our/portlet/url',
           data: {
           userVar: userVar
         },
         error: function() {
           jQuery('.article-results').html('' + 
                   Liferay.Language.get('sorry-there-was-an-error') + '');
         },
         success: function(message) {
           jQuery('.article-results').html(message);
         }
       );
     }
   }
 );


Hope this helps...




Comments

Popular posts from this blog

Shell Script to check tomcat status and restart

The below script checks the status of a particular tomcat status and restarts it if the tomcat does not respond....TOMCAT_HOME=/usr/local/tomcat-folder/

is_Running ()
{

        wget -O - http://yourserver.com/ >& /dev/null
 if( test $? -eq 0 ) then
  return 0
 else
  return 1
 fi
}


kill_Hanged_Processes ()
{
 echo "killing hanged processes......"
 javaProcs=`ps -efl| grep -v grep | grep java`
 if(test ! -z "$javaProcs") then
  echo "nonzero"
  processId=`echo $javaProcs | awk '{ print $2} '`
  echo "$processId"
  kill -9 $processId
 fi
}
stop_Tomcat ()
{
 echo "shutting down......"
 $TOMCAT_HOME/bin/shutdown.sh
}

start_Tomcat ()
{
 echo "starting......"
 $TOMCAT_HOME/bin/startup.sh
}

restart ()
{
 stop_Tomcat
 sleep 10
 kill_Hanged_Processes
 start_Tomcat
 sleep 60
}

send_Mail ()
{
#!/bin/bash
# script to send simple email
# email subject
SUBJECT="Telegraphindia.com went down"
# Email To ?
EMAIL="mailid1@gmail.com,mailid2@gmail.com"
# Em…

Getting access to menu from portlet in liferay

The below code describes the way of accessing menu items from the portlet. Here i have called it from jsp. The best thing about this is you can use the beautiful permission management of menu items of liferay as well without bothering about that. Writing services for fetching menu names from the layout tables will need more codes for permission managements......

Hope this helps.........


<%--
/**
* Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
--%>
<%@ page import="com.li…

Virus f Opyum Team

Symptoms :: 
Several processes running named f or i. 
Network choked
Apache Dead
Unknown entry  * * * * * root f Opyum Team in crontab

Investigate ::
Try to kill the f process and even root will be unable to kill it. Check file named f and i in /etc or /bin or /usr/sbin directory. Try to delete, the file f  will not delete.  Some unknown .jpg files will be there in the same folder. 

Solve :: The root is unable to delete the file f because of the immutable bit in f
To remove it use ses or chattr
Follow the below steps to remove it completely.....



remove the unknown .jpg files in system folders

#top
(kill process f) option k

#ses -i /bin/f
#rm /bin/f
#ses -i /etc/crontab
#vi /etc/crontab (and delete last line)
#reboot


Precautions ::  In my case the server was hacked bu Brute-force attack
So set a good password with a combination of upper,lower case letters and special characters.

Post your feedback or any issues you may face removing the virus.  Very less number of good threads are there explaining …