且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Liferay中的Portlet间通信

更新时间:2023-02-23 22:28:41

有几种不同的方法可以使Portlet相互通信.大多数文档都包含在后裔

There are a couple of different ways to have portlets talk with each other. Most are covered under the documentation of IPC's and the descendant pages.

对于您而言,您应该真正查看

In your case, you should really look at the client-side page:

具有基本结构

<a href="javascript:void(0)" class="comm-demo">demo[number]</a>

您将在发送器portlet"上使用此JS:

You would have this JS on the "transmitter portlet":

// you may need to have jQuery instead of $. Liferay may have its own 
// $ function which jQuery shouldn't mess with.
$( function () { 
      $('a.comm-demo').click( function(event) { 
           var txt = $(this).next().val(); // demo<number> 
           Liferay.trigger('click', {text: txt}); 
           return false; 
      }); 
 });

然后在接收portlet"上:

Then on the "receiving portlet(s)":

 Liferay.bind( 
      'click', 
      function(event, data) { 
           var txt = data.text;
           // this will set all class-of-fields to have the text 
           // "demo<number from above>Portlet"
           $('.class-of-fields')[0].html(txt + "Portlet"); 
           // I believe there is a way to minimize/maximize a portlet by 
           // simulating a mouse click, but research would be needed to 
           // confirm.
 });