Portal Showcase

Note: Liferay Portal has three types of resources, each having associated permissions:

  1. Portlet Resource: Permissions associated with the UI of the portlet, such as permission to VIEW the portlet.
  2. Top-Level Model Resource: Permissions associated with the database entity itself, such as permission to ADD a row.
  3. Row-Level Model Resource: Permissions associated with individual rows of the database entity, such as permission to UPDATE a row.

portal:permissionsURL

PermissionsURL is a UIOutput component that generates a URL pointing to the Liferay Portal Permissions UI. If the var attribute is present, the component introduces a variable into the EL. Otherwise, the URL is written to the response.

General Usage

Access the Portlet Resource Permissions by specifying the primary key of a portlet via the resourcePrimKey attribute, and optionally specifying roleTypes in order to control which roles are displayed in the Liferay Portal Permissions UI.
http://liferayfaces.org/web/guest/portal-showcase?p_p_id=com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet&p_p_lifecycle=0&p_p_state=maximized&p_p_col_id=column-1&p_p_col_count=1&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_mvcPath=%2Fedit_permissions.jsp&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_redirect=%2Fweb%2Fguest%2Fportal-showcase%2F-%2Fportal-tag%2Fportal%2Fpermissionsurl%2Fgeneral&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_returnToFullPageURL=%2Fweb%2Fguest%2Fportal-showcase%2F-%2Fportal-tag%2Fportal%2Fpermissionsurl%2Fgeneral&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_portletConfiguration=true&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_portletResource=1_WAR_comliferayfacesdemoportalshowcaseportlet&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_modelResource=&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_modelResourceDescription=&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_resourceGroupId=20147&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_resourcePrimKey=30794_LAYOUT_1_WAR_comliferayfacesdemoportalshowcaseportlet
http://liferayfaces.org/web/guest/portal-showcase?p_p_id=com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet&p_p_lifecycle=0&p_p_state=maximized&p_p_col_id=column-1&p_p_col_count=1&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_mvcPath=%2Fedit_permissions.jsp&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_redirect=%2Fweb%2Fguest%2Fportal-showcase%2F-%2Fportal-tag%2Fportal%2Fpermissionsurl%2Fgeneral&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_returnToFullPageURL=%2Fweb%2Fguest%2Fportal-showcase%2F-%2Fportal-tag%2Fportal%2Fpermissionsurl%2Fgeneral&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_portletConfiguration=true&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_portletResource=1_WAR_comliferayfacesdemoportalshowcaseportlet&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_modelResource=&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_modelResourceDescription=&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_resourceGroupId=20147&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_resourcePrimKey=30794_LAYOUT_1_WAR_comliferayfacesdemoportalshowcaseportlet&_com_liferay_portlet_configuration_web_portlet_PortletConfigurationPortlet_roleTypes=1
			

Source Code

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:portal="http://liferay.com/faces/portal" xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

	<!-- Example 1: Introducing a var into the EL with default role types (Guest, Owner, Power User, Site Member, User) -->
	<portal:permissionsURL resourcePrimKey="#{permissionsURLModelBean.portletResourcePrimaryKey}" var="permissionsURL1" />
	<pre>#{permissionsURL1}</pre>
	<h:panelGroup rendered="#{liferay.userHasPortletPermission['PERMISSIONS']}">
		<button onclick="document.location='#{permissionsURL1}'; return false;">#{i18n['permissions']}</button>
	</h:panelGroup>

	<!-- Example 2: Output directly to the response with specific role types (Guest, Owner, Power User, User) -->
	<pre>
		<portal:permissionsURL resourcePrimKey="#{permissionsURLModelBean.portletResourcePrimaryKey}"
			roleTypes="#{permissionsURLModelBean.roleConstants.TYPES_REGULAR}" />
	</pre>
	<portal:permissionsURL resourcePrimKey="#{permissionsURLModelBean.portletResourcePrimaryKey}"
		roleTypes="#{permissionsURLModelBean.roleConstants.TYPES_REGULAR}" var="permissionsURL2" />
	<h:panelGroup rendered="#{liferay.userHasPortletPermission['PERMISSIONS']}">
		<button onclick="document.location='#{permissionsURL2}'; return false;">#{i18n['permissions']}</button>
	</h:panelGroup>

</ui:composition>
@RequestScoped
@ManagedBean
public class PermissionsURLModelBean {

	// Private Data Members
	private String portletResourcePrimaryKey;
	private Map<String, Object> roleConstants;

	public String getPortletResourcePrimaryKey() {

		if (portletResourcePrimaryKey == null) {
			long plid = LiferayPortletHelperUtil.getPlid();
			Portlet portlet = LiferayPortletHelperUtil.getPortlet();
			String portletId = portlet.getPortletId();
			portletResourcePrimaryKey = PortletPermissionUtil.getPrimaryKey(plid, portletId);
		}

		return portletResourcePrimaryKey;
	}

	public Map<String, Object> getRoleConstants() {

		if (roleConstants == null) {

			roleConstants = new HashMap<String, Object>();

			Field[] fields = RoleConstants.class.getFields();

			for (Field field : fields) {
				int modifiers = field.getModifiers();

				if (Modifier.isStatic(modifiers)) {

					try {
						roleConstants.put(field.getName(), field.get(null));
					}
					catch (IllegalAccessException e) {
						// ignore
					}
				}

			}
		}

		return roleConstants;
	}
}
Liferay Faces Bridge Implementation 4.0.0 + Liferay Faces Portal 3.0.0 + Showcase Common 3.0.0 + Liferay Faces Util 3.0.0 + Mojarra 2.2.13