Fórum

Creating new actions and checking those actions in a JSP

C Endle, modificado 12 Anos atrás.

Creating new actions and checking those actions in a JSP

New Member Postagens: 7 Data de Entrada: 03/10/11 Postagens Recentes
Hi,

I am using Liferay 6.1 CE bundled with Tomcat.

I have a sample portlet that defines some new actions. After deploying the port let, if I go into portlet configuration tab, I can see the new actions that I added under the permissions tab. However, when I attempt to check for that action in the view.jsp, I am getting an error com.liferay.portal.NoSuchResourceActionException.

Here is what I have:

Used the Eclipse wizard to create an MVC portlet called ProposalPortlet.

Under WEB-INF/src, created portlet.properties. This points to my resource actions

resource.actions.configs=resource-actions/default.xml 


Under WEB-INF/src/resource-actions/ there is a file called default.xml. This file has my new actions in it.


<!--?xml version="1.0"?-->

<resource-action-mapping>

	<portlet-resource>
		<portlet-name>proposal-portlet</portlet-name>
		
		<permissions>
			<supports>
				<action-key>ADD_TO_PAGE</action-key>
				<action-key>CONFIGURATION</action-key>
				<action-key>VIEW</action-key>
				<action-key>PROPOSAL-CREATE</action-key>
				<action-key>PROPOSAL-VIEW</action-key>
				<action-key>PROPOSAL-COMMENT</action-key>
				<action-key>PROPOSAL-EDIT</action-key>
			</supports>
			<site-member-defaults>
				<action-key>VIEW</action-key>
			</site-member-defaults>
			<guest-defaults>
				<action-key>VIEW</action-key>
			</guest-defaults>
			<guest-unsupported />
		</permissions>
	</portlet-resource>

</resource-action-mapping>



<portlet-name>proposal-portlet</portlet-name> --- This is the same name used in the portlet.xml to define this portlet.

In the view.jsp, I have a call to check permissions

&lt;%@include file="/html/init.jsp"%&gt;

&lt;%
    String className = "proposal-portlet";

    // ** THIS FAILS **
    boolean hasProposalCreatePermission = permissionChecker.hasPermission(
			scopeGroupId, className,
			scopeGroupId, "PROPOSAL-CREATE");

     // this works
     boolean hasProposalViewPermission = permissionChecker.hasPermission(
			scopeGroupId, Group.class.getName(), scopeGroupId,
			ActionKeys.PERMISSIONS);
%&gt;


Refreshing the portlet gives me the following error:

22:04:27,735 ERROR [AdvancedPermissionChecker:944] com.liferay.portal.NoSuchResourceActionException: proposal-portlet#PROPOSAL-CREATE

Does anyone know why I am getting this exception? Why can't I access the new actions?

Thanks,
Cory
Luigi Molinaro, modificado 11 Anos atrás.

RE: Creating new actions and checking those actions in a JSP

New Member Postagens: 13 Data de Entrada: 29/05/12 Postagens Recentes
I have the same problem. Have you solved?
Sameer Srivastava, modificado 11 Anos atrás.

RE: Creating new actions and checking those actions in a JSP

New Member Postagens: 14 Data de Entrada: 22/08/12 Postagens Recentes
Hi guys,

I am facing the same problem.
Did any of you could resolve it ?

Regards,

Sameer
C Endle, modificado 11 Anos atrás.

RE: Creating new actions and checking those actions in a JSP

New Member Postagens: 7 Data de Entrada: 03/10/11 Postagens Recentes
I have not resolved this issue yet.

Regards,
Cory
thumbnail
Jan Geißler, modificado 11 Anos atrás.

RE: Creating new actions and checking those actions in a JSP

Liferay Master Postagens: 735 Data de Entrada: 05/07/11 Postagens Recentes
You are Checking for a Resource Permission, not a portlet Permission.

However:

boolean hasProposalCreatePermission = permissionChecker.hasPermission(
            scopeGroupId, portletName,
            scopeGroupId, "PROPOSAL-CREATE");



this should work as the API states:

hasUserPermission

boolean hasUserPermission(long groupId,
String name,
String primKey,
String actionId,
boolean checkAdmin)
Returns true if the user has permission to perform the action on the resource without using guest permissions.
Parameters:
groupId - the primary key of the group containing the resource
name - the resource's name, which can be either a class name or a portlet ID
primKey - the primary key of the resource
actionId - the action ID
checkAdmin - whether to use permissions gained from administrator roles
Returns:
true if the user has permission to perform the action on the resource without using guest permissions; false otherwise