Rather then have a series of buttons or menus with actions in the different views of the app, you can move all of these actions to the upper right menu of the administrative portlet, leaving the primary action (often an “Add” operation) visible in the add menu. For example, the web content application has the actions menu shown below:
Figure 1: The upper right ellipsis menu contains most of the actions for the app.
Follow these steps to configure the actions menu in your admin app:
-
Create a
*ConfigurationIcon
Component class for the action that extends theBasePortletConfigurationIcon
class and implements thePortletConfigurationIcon
service:@Component( immediate = true, service = PortletConfigurationIcon.class ) public class MyConfigurationIcon extends BasePortletConfigurationIcon { ... }
-
Override the
getMessage()
method to specify the action’s label:@Override public String getMessage(PortletRequest portletRequest) { ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute( WebKeys.THEME_DISPLAY); ResourceBundle resourceBundle = ResourceBundleUtil.getBundle( themeDisplay.getLocale(), ExportAllConfigurationIcon.class); return LanguageUtil.get(resourceBundle, "export-all-settings"); }
-
Override the
get()
method to specify whether the action is invoked with theGET
orPOST
method:@Override public String getMethod() { return "GET"; }
-
Override the
getURL()
method to specify the URL (oronClick
JavaScript method) to invoke when the action is clicked:@Override public String getURL( PortletRequest portletRequest, PortletResponse portletResponse) { LiferayPortletURL liferayPortletURL = (LiferayPortletURL)_portal.getControlPanelPortletURL( portletRequest, ConfigurationAdminPortletKeys.SYSTEM_SETTINGS, PortletRequest.RESOURCE_PHASE); liferayPortletURL.setResourceID("export"); return liferayPortletURL.toString(); }
-
Override the
getWeight()
method to specify the order that the action should appear in the list:@Override public double getWeight() { return 1; }
-
Override the
isShow()
method to specify the context in which the action should be displayed:@Override public boolean isShow(PortletRequest portletRequest) { return true; }
-
Define the view where you want to display the configuration options. By default, if the portlet uses
mvcPath
, the global actions (such as configuration, export/import, maximized, etc.) are displayed for the JSP indicated in the initialization parameter of the portletjavax.portlet.init-param.view-template=/view.jsp
. The value indicates the JSP where the global actions should be displayed. However, if the portlet uses MVC Command, the views for the global actions must be indicated with the initialization parameterjavax.portlet.init-param.mvc-command-names-default-views=/wiki_admin/view
and the value must contain themvcRenderCommandName
where the global actions should be displayed. -
If the portlet can be added to a page and you want to always include the configuration options, add this initialization parameter to the portlet’s properties:
javax.portlet.init-param.always-display-default-configuration-icons=true
In this example, the action appears in the System Settings portlet. To make it appear in a secondary screen, you can use the
path
property as shown below. The value of thepath
property depends on the MVC framework used to develop the app. For the MVCPortlet framework, provide the path (often a JSP) from themvcPath
parameter. For MVCPortlet with MVC Commands, the path should contain themvcRenderCommandName
where the actions should be displayed (such as/document_library/edit_folder
for example):@Component( immediate = true, property = { "javax.portlet.name=" + ConfigurationAdminPortletKeys.SYSTEM_SETTINGS, "path=/view_factory_instances" }, service = PortletConfigurationIcon.class ) public class ExportFactoryInstancesIcon extends BasePortletConfigurationIcon { @Override public String getMessage(PortletRequest portletRequest) { ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute( WebKeys.THEME_DISPLAY); ResourceBundle resourceBundle = ResourceBundleUtil.getBundle( themeDisplay.getLocale(), ExportFactoryInstancesIcon.class); return LanguageUtil.get(resourceBundle, "export-entries"); } @Override public String getMethod() { return "GET"; } @Override public String getURL( PortletRequest portletRequest, PortletResponse portletResponse) { LiferayPortletURL liferayPortletURL = (LiferayPortletURL)_portal.getControlPanelPortletURL( portletRequest, ConfigurationAdminPortletKeys.SYSTEM_SETTINGS, PortletRequest.RESOURCE_PHASE); ConfigurationModel factoryConfigurationModel = (ConfigurationModel)portletRequest.getAttribute( ConfigurationAdminWebKeys.FACTORY_CONFIGURATION_MODEL); liferayPortletURL.setParameter( "factoryPid", factoryConfigurationModel.getFactoryPid()); liferayPortletURL.setResourceID("export"); return liferayPortletURL.toString(); } @Override public double getWeight() { return 1; } @Override public boolean isShow(PortletRequest portletRequest) { ConfigurationModelIterator configurationModelIterator = (ConfigurationModelIterator)portletRequest.getAttribute( ConfigurationAdminWebKeys.CONFIGURATION_MODEL_ITERATOR); if (configurationModelIterator.getTotal() > 0) { return true; } return false; } @Reference private Portal _portal; }
This covers some of the available methods. See the Javadoc for a complete list of the available methods.
Great! Now you know how to configure your admin app’s actions.