How To Add A Portlet To The Control Panel – Liferay

Most of the time, we may come up with situations where we have to provide an option for the portal administrator to do a specific set of activities on a particular Liferay portlet’s configuration or data.

In this post, we will see how to add a Liferay portlet to the control panel.

We will also see how to disable adding the portlets to other pages, except the control panel.

We are using the Liferay developer studio IDE(LDS) for creating the Liferay portlet.

Version details: Liferay 6.2

Creating the liferay portlet

Create a new liferay plugin project from File > New > Liferay Plugin Project. Name it as ControlPanelExample. You can skip this if you already have a plugin project created already.

Create a new liferay portlet from File > New > Liferay Portlet. Let’s give the portlet class as AdminPortlet, as shown below. Click on the Next button to go to the next step.

2

Click on the Next button(as we are not modifying any configuration here), and you will be getting the following configuration window.

3

In this configuration window, we are configuring the portlet to make it a control panel portlet.

Here, we select the check box Add to Control Panel.

Also, select the control panel category for the portlet. We have chosen Control Panel – Apps category.

Keep the default Entry weight as 1.5

To make the portlet available only under the control panel, select Display Category as hidden.

Finally, click on the Finish button and deploy the portlet.

Adding portlet to control panel

We can view our portlet under Admin > Control Panel > Apps section as shown below.

We can observe our Admin portlet below.

5

The configurations we have selected earlier while creating the portlet on the portlet’s configuration window will modify mainly the liferay-portlet.xml and the liferay-display.xml files.

Liferay ads an <control-panel-entry-category> entry to the liferay-portlet.xml file to determine under which control panel category portlet should be listed.

Also, Liferay uses an <control-panel-entry-weight> entry to specify the weightage for displaying the portlet where it is listed.

The following code gets added to the liferay-display.xml file. Here, the category name is specified as category.hidden that makes the Liferay portlet invisible to add for any site pages.

<display> 
    <category name="category.hidden"> 
        <portlet id="admin"></portlet> 
    </category>
</display>

By setting the <control-panel-entry-category> tag’s value to the content on the liferay-portlet.xml file, we can add the portlet to the Admin > Content section as shown below.

4

Conclusion

In this post, we learned how to add a Liferay portlet to the control panel.

How To Add A Portlet To The Control Panel – Liferay
Scroll to top

Discover more from ASB Notebook

Subscribe now to keep reading and get access to the full archive.

Continue reading