Most of the times we may come up with situations where we have to provide an option for the portal administrator to do certain set of activities on particular liferay portlet’s configuration or data. In this post we will see how to add liferay portlet to control panel. We also see how to disable adding portlet to other pages, except control panel.
- 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 portlet class as AdminPortlet as shown below. Click on Next button to go to next step.
- Click on Next button(as we are not modifying any configuration here) and you will be getting following configuration window. In this configuration window, we are configuring the portlet to make it a control panel portlet.
- Here, we have have to select the check box Add to Control Panel.
- Select under which control panel category portlet should be added. We have chosen Control Panel – Apps category.
- Keep the default Entry weight as 1.5
- To make the portlet available only under control panel, select Display Category as hidden.
- Finally click on Finish button and deploy the portlet.
- We can view our portlet now under Admin > Control Panel > Apps section as shown below. We can see our Admin portlet.
- Here these configurations we have selected earlier while creating the portlet on portlet’s configuration window, will modify mainly liferay-portlet.xml and liferay-display.xml files.
- A <control-panel-entry-category> entry will be added to liferay-portlet.xml file to determine under which control panel category, portlet should be listed.
- A <control-panel-entry-weight> entry is added to specify the weight-age for displaying the portlet where it is listed.
- liferay-display.xml file will be added with following code. Here category name specified as category.hidden, 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> value to content on liferay-portlet.xml file, we can add the portlet to Admin > Content section as shown below:
Summary: In this post we learned how to add a liferay portlet to control panel. Also check our liferay related posts.
Note: Version used: Liferay 6.2 + Apache Tomcat 7.