1)For Client
Liferay.fire('eventName',{
parameter1: value1,
parameter2: value2
parameter1: value1,
parameter2: value2
});
2)For Receiver
Liferay.on('eventName',function(event) {
var firstValue = event.parameter1,
var secondValue = event.parameter2
var firstValue = event.parameter1,
var secondValue = event.parameter2
});
We take a simple scenario where user can select food type from one portlet and second portlet shows food items on the basis of first portlet.Here we create two project and each project contain one portlet.
So lets start this step by step:-
For Sender
Step 1:-Create Liferay Project and Portlet
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as client-side-sender and click finish. After that Right Click on your project and click on New than click on Liferay Portlet. Provide class and package name and select MVCPortlet and click finish.
Step 2:-Change view.jsp
Open view.jsp and paste this:-
Open view.jsp and paste this:-
Explanation:-
- On click of button we fetch the value of selected radio button and set in foodType.
- We give the eventName as selectedFoodType which is used to fetch the data in receiver.
Note:-Change <requires-namespaced-parameters> is false inside liferay-portlet.xml.
For Receiver
Step 1:-Create Liferay Project and Portlet
Similarly as in Sender Create project with name client-side-sender and create a portlet in it.
Step 2:-Change view.jsp
Open view.jsp and paste this:-
Open view.jsp and paste this:-
Explanation:-
Here we get the value from event and on the basis of input we show the output.
For Output
Now deploy both sender and receiver portlet and add to same page .
Now Select Vegetarian and click submit
Select Non-Vegetarian and click submit