Reputation: 143
When an instance of my portlet is going to be removed from a page, I want to capture that event to get some preference values from that portlet, and to do something.
Is there anything like interfaces or hooks to do that in Liferay?
Upvotes: 5
Views: 1021
Reputation: 2509
You can define your own PortletLayoutListener
in liferay-portlet.xml:
<portlet>
<portlet-name>xxyyzz</portlet-name>
...
<portlet-layout-listener-class>com.myCompany.MyLayoutTypePortletListener</portlet-layout-listener-class>
...
</portlet>
And your MyLayoutTypePortletListener may be similar to:
public class MyLayoutTypePortletListener
implements PortletLayoutListener {
public void onRemoveFromLayout(String portletId, long plid)
throws PortletLayoutListenerException {
// ***** ... your LOGIC HERE *****
}
public void onMoveInLayout(String portletId, long plid)
throws PortletLayoutListenerException {
}
public void onAddToLayout(String portletId, long plid)
throws PortletLayoutListenerException {
}
}
See the journal content portlet for an example and that Liferay's Forum Post.
Upvotes: 10