问题
I am new in liferay. So, I just want to explain my scenario.
Actually I have two portlet on my web page - one is in left side and other is on right side:
- he left side portlet contains two hyperlink say demo1 & demo2.
- And I have another two portlet say demo1Portlet & demo2Portlet.
- Instead of right side portlet "demo1Portlet" will be displayed by default.
- Now what I have to do is, if I click on demo2 link then, right side portlet will change and it will display "demo2Portlet" and if I click on demo1 link then it will display "demo1Portlet" on right side.
Can any one know how I can achieve this task?
Please reply to me as soon as possible.
I am new to liftray, so I don't know whther this can be achieved through IPC or without it. Please explain whatever will be the way.
Thanks.
回答1:
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:
With your basic structure
<a href="javascript:void(0)" class="comm-demo">demo[number]</a>
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;
});
});
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.
});
来源:https://stackoverflow.com/questions/6853730/inter-portlet-communication-in-liferay