How to capture the portlet instance removing event from a page in Liferay?
Asked Answered
D

1

5

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?

Dissenter answered 4/12, 2012 at 7:41 Comment(0)
O
10

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.

Optative answered 4/12, 2012 at 16:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.