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?
You have to go to the left side vertical menu and click on "Modify Controls" where you see the covered eye. After this, you can see on all the portlets the settings Icon and you can remove each of them.
portlet have similar lifecycle as that of a servlet, portlet needs a portlet container similar to a servlet, we know that servlet have lifecycle of init(), service() and destroy() similarly liferay's lifecycle have the following stages.
Web apps in Liferay DXP are called portlets. Like many web apps, portlets process requests and generate responses. In the response, the portlet returns content (e.g. HTML, XHTML) for display in browsers.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With