Thursday, 16 July 2015

How to add liferay portlet under one of the secions of control panel

Many a times it is the requirement that we want to see our custom portlet under one of the sections of the control panel. In liferay it is possible to do it by following few simple steps.

Here are the two simple steps available to get it done:

1) Modify liferay-portlet.xml file to specify where in control panel we want to see our portlet
2) Run and Verify

Here are the steps in detailed:

1) Modify liferay-portlet.xml file to specify where in control panel we want to see our portlet

Here is the sample code snippet of the liferay-portlet.xml

<liferay-portlet-app>
<portlet>
<portlet-name>StudentPage</portlet-name>
<icon>/icon.png</icon>
:
<control-panel-entry-category>portal</control-panel-entry-category>
<control-panel-entry-weight>100</control-panel-entry-weight>
:
</portlet>
</liferay-portlet-app>


As we can see that there are mainly two properties

I) "<control-panel-entry-category>" which controls under which section of the control panel our portlet should be visible.

Here we can specify one of the four values

i) my
ii) content
iii) portal
iv) server

In our case we have specified "portal" so our portlet "StudenPage" will be available under "portal" section.

II) "<control-panel-entry-weight>" and we need to set to see the custom portlet inside one of the sections of the control panel.

Here we need to specify the weight of the portlet. Higher the weight will show our portlet in lower portion.

In our case we have specified "100" means that across all the portlet under "portal" our portlet would come more on the bottom side.


2) Run and Verify

We are just a one step away to see our custom portlet inside control panel. Just build and deploy latest war file. Once we see that "StudentPage" (In our case) is available
for use just go over the control panel of the liferay, scroll down to "Portal" section and see your portlet would be available with other OOTB portlet.

FYI, liferay provides one more property inside same file called "<control-panel-entry-class>". This can be used if we want to specify custom logic that portlet
should be visible to only spefic set of roles. Then we can specify class name in this property. Basically custom class which we write should implement
"com.liferay.portlet.ControlPanelEntry" interface. "ControlPanelEntry" interface has the method "isVisible" which will be called where we can write our custom logic.

Reader may go through "com.liferay.portlet.BaseControlPanelEntry" class to checkout by default portlet would be visible to which all roles.

Cheers!
Henal Saraiya
(Lead Consultant)
CIGNEX Datamatics

No comments:

Post a Comment