« Back

Adding a Plugins Portlet to the Control Panel

Company Blogs December 30, 2008 By Minhchau Dang Staff

A "Gotcha!" situation came up today when I attempted to add a portlet developed in the plugins environment to the Control Panel (which is a new feature being developed for 5.2.0 that you can read about in Jorge's blog entry).

In a nutshell, the Control Panel provides a centralized administrative interface for the entire portal. Unlike a standard layout where you 'manage pages' and put portlets anywhere, whether or not a portlet shows up inside of the Control Panel depends on whether or not you've set the following nodes in your liferay-portlet.xml:

  • control-panel-entry-category: The 'category' where your portlet will appear. There are currently 4 valid values for this element: 'my', 'content', 'portal', and 'server'.
  • control-panel-entry-weight: Determines the relative ordering for your portlet within a given category. The higher the number, the lower in the list your portlet will appear within that category.
  • control-panel-entry-class: The name of a class that implements the ControlPanelEntry interface which determines who can see the portlet in the control panel via an isVisible method.

By making sure to define these elements in your liferay-portlet.xml, you can theoretically add any portlet (whether they be portlets built in the Extensions environment or Plugins environment) to the new Control Panel interface.

In my case, I couldn't think of a page/layout which would fit for the plugin I was developing, but since it had administrative elements to it, I felt the best place for it would be the Control Panel. So, I updated the dtd for liferay-portlet.xml to 5.2.0 and added the appropriate control panel elements.

Unexpectedly, the new plugin portlet did not show up in the Control Panel.

After debugging com.liferay.portal.util.PortalImpl, I verified that the portlet was recognized as a Control Panel portlet, and that it was added it to the java.util.Set, but by the time it returned from the method, the portlet had disappeared. I was at a loss for why.

However, it turns out those abstract algebra classes that I took in college came in handy, and I realized where the "Gotcha!" was hidden:

Set portletsSet = new TreeSet(
	new PortletControlPanelWeightComparator());

By their mathematical definition, every element in a set must be unique. After checking com.liferay.portal.util.comparator.PortletControlPanelWeightComparator, I discovered that the control panel render weight is the only thing that matters for determining uniqueness of a portlet within a Control Panel category. As long as render weights are equal, they are treated as the same portlet.

In summary, my portlet shared the same render weight as another Control Panel portlet (I gave it the same render weight as My Account because I copy-pasted), so it was getting replaced as soon as the My Account portlet was added to the java.util.TreeSet. Thus, why it was clearly being added but disappeared by the time it returned from the method.

So, in the event that you are planning to leverage the new Control Panel feature for portlets that you're developing, bear in mind that you need to keep your render weights different from the portlets which exist in Liferay and from other portlets you may want to add to your Liferay instance, and you'll be okay.

Alternatively, you could extend com.liferay.portal.util.PortalImpl, override the definition of getControlPanelPortlets, and use a different comparator which checks portlet ids as well in the event of ties.

Threaded Replies Author Date
Hi Minhchau, Good Point! The control panel... Jonas Yuan December 30, 2008 10:20 PM
Hey Minchau, Nice catch! I think we should fix... Jorge Ferrer January 2, 2009 5:32 AM
Sure thing. ... Minhchau Dang January 2, 2009 11:14 AM
Doesn't it make more sense to add these... Peter Mesotten April 2, 2009 12:45 AM
Still unable to see my portlets in the control... Gordon Augat December 29, 2009 4:10 PM
I found the problem. In the liferay-portlet.xml... Gordon Augat December 30, 2009 6:17 PM
Also you need to set instanceable to false... Waseem Zawaideh September 27, 2010 4:26 AM
[...] Hola, Aquí hay un pequeño tutorial:... Anonymous July 25, 2011 8:24 AM
[...] Hi Rashmi, Check this link (If you want... Anonymous November 21, 2011 11:44 PM
Nice post. For a case which is vise versa - I... Roshan Qureshi December 18, 2013 12:03 AM

Hi Minhchau,

Good Point! The control panel render weight for control-panel-entry-weight is the only thing that matters for determining uniqueness of a portlet within a control panel category.


Jonas Yuan
Posted on 12/30/08 10:20 PM.
Hey Minchau,

Nice catch! I think we should fix it. I guess it would be as simple as considering the portlet name in the comparison if the weights are equal within PortletControlPanelWeightComparator()

What do you think? Could you take care of it?
Posted on 1/2/09 5:32 AM.
Doesn't it make more sense to add these elements to liferay-display.xml?
Posted on 4/2/09 12:45 AM.
Still unable to see my portlets in the control panel even with unique weight. Any ideas?
Posted on 12/29/09 4:10 PM.
I found the problem. In the liferay-portlet.xml file, make sure that "ajaxable" is set to false for your portlet.
Posted on 12/30/09 6:17 PM in reply to Gordon Augat.
Also you need to set instanceable to false before it can be displayed
Posted on 9/27/10 4:26 AM.
[...] Hola, Aquí hay un pequeño tutorial: http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Control+Panel Ejemplo sobre ControlPanelEntry, ojo extendemos BaseControlPanelEntry (ver tutorial)... [...] Read More
Posted on 7/25/11 8:24 AM.
[...] Hi Rashmi, Check this link (If you want to display your custom portlet on click of that link in control panel) http://www.liferay.com/web/minhchau.dang/blog/-/blogs/1857476 Check liferay-portlet.xml... [...] Read More
Posted on 11/21/11 11:44 PM.
Nice post.
For a case which is vise versa - I want to add control panel portlet on portal page, currently we have to create ext to add a OOB liferay portlet on the portal page.

Its a common feature in many liferay portal requirements and so we should be able to achieve this by minimum efforts by some configurations only.

I have created one request for this feature to Liferay.

Please vote for this if you like it.


Roshan Qureshi
Posted on 12/18/13 12:03 AM.