I want to add my custom portlet to control panel programmatically. How can I do it ?
2 Answers
As you probably already know which portlet to make available in ControlPanel (there is only a limited number of portlets you write, right?) you don't need to make it fully programmatic, but can actually declare it like any other ControlPanel Portlet you have. (see your other question for information)
However, in order to make your administrative portlet to appear/disappear based on dynamic information, you can use the declaration of this element (taken from http://www.liferay.com/dtd/liferay-portlet-app_6_0_0.dtd)
<!--
The control-panel-entry-class value must be a class that implements
com.liferay.portlet.ControlPanelEntry and is called by the Control Panel to
decide whether the portlet should be shown to a specific user in a specific
context. The default value is set in portal.properties.
See:
http://docs.liferay.com/portal/6.0/javadocs/portal-service/com/liferay/portlet/ControlPanelEntry.html
-->
<!ELEMENT control-panel-entry-class (#PCDATA)>
-
Nice explanation, I failed to see it from this point of view (_As you probably already know which portlet to make available in ControlPanel_). So for control panel it is actually not required to "add" it programmatically rather it should be to show/hide it programmatically. Well, for the end-user I don't think it would make any difference. I would have marked this as an answer. – Prakash K Dec 31 '12 at 06:06
I think it is programmatically not-possible, since:
The portlets on Control Panel page are not stored in database as is the case for other pages in the portal in which the portlets are stored as
typeSettings
in theLayout
table.Instead the portlets that go on the control-panel page are determined by the value of the field
_controlPanelEntryCategory
inPortletImpl
which denotes the value of tag<control-panel-entry-category>
inliferay-portlet.xml
and this value is set for each portlet by thePortletLocalServiceImpl#_readLiferayPortletXML
method which I think is only called everytime either when the server starts (ininitEAR()
) or a portlet is deployed (ininitWAR()
).
So it is required to have an entry in the liferay-portlet.xml
for the different <control-panel-entry-*>
tags to be able to add the portlet to control panel. And this is not possible programmatically.
This is as per my reasoning and understanding, but I would like to hear from Liferay masters if this is at all possible.

- 11,669
- 6
- 51
- 109