生命中的内部portlet通信

时间:2011-07-28 03:15:49

标签: java liferay portlet

我是liferay的新手。所以,我只想解释一下我的情景。

实际上我的网页上有两个portlet - 一个位于左侧,另一个位于右侧:

  • 他左侧的portlet包含两个超链接,例如demo1& DEMO2。
  • 我还有两个portlet说demo1Portlet& demo2Portlet。
  • 将显示右侧portlet“demo1Portlet” 默认值。
  • 现在我要做的是,如果我点击demo2链接,那么,右边 portlet将更改,它将显示“demo2Portlet”,如果我单击 在demo1链接上,它将在右侧显示“demo1Portlet”。

任何人都知道如何完成这项任务吗?

请尽快回复我。

我是lifrapy的新手,所以我不知道通过IPC还是没有它可以实现这一目标。请解释一下会有什么方法。

感谢。

1 个答案:

答案 0 :(得分:2)

有两种不同的方法可以让portlet相互通信。大多数内容都包含在IPCdescendant pages的文档中。

在您的情况下,您应该真正查看client-side页面:

使用您的基本结构

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

你可以在“发射器portlet”上使用这个JS:

// 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”上:

 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.
 });
相关问题