Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 465
bopomofu Avatar asked Dec 04 '12 07:12

bopomofu


People also ask

How do I remove portlet page from 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.

What is the Life cycle of a portlet?

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.

What is portlet in Liferay?

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.


1 Answers

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.

like image 141
Tony Rad Avatar answered Nov 15 '22 08:11

Tony Rad