Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
C Endle
Creating new actions and checking those actions in a JSP
March 5, 2012 2:39 PM
Answer

C Endle

Rank: New Member

Posts: 7

Join Date: October 3, 2011

Recent Posts

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

1resource.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.

 1
 2<?xml version="1.0"?>
 3<!DOCTYPE resource-action-mapping PUBLIC "-//Liferay//DTD Resource Action Mapping 6.1.0//EN" "http://www.liferay.com/dtd/liferay-resource-action-mapping_6_1_0.dtd">
 4<resource-action-mapping>
 5
 6    <portlet-resource>
 7        <portlet-name>proposal-portlet</portlet-name>
 8       
 9        <permissions>
10            <supports>
11                <action-key>ADD_TO_PAGE</action-key>
12                <action-key>CONFIGURATION</action-key>
13                <action-key>VIEW</action-key>
14                <action-key>PROPOSAL-CREATE</action-key>
15                <action-key>PROPOSAL-VIEW</action-key>
16                <action-key>PROPOSAL-COMMENT</action-key>
17                <action-key>PROPOSAL-EDIT</action-key>
18            </supports>
19            <site-member-defaults>
20                <action-key>VIEW</action-key>
21            </site-member-defaults>
22            <guest-defaults>
23                <action-key>VIEW</action-key>
24            </guest-defaults>
25            <guest-unsupported />
26        </permissions>
27    </portlet-resource>
28
29</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

 1<%@include file="/html/init.jsp"%>
 2
 3<%
 4    String className = "proposal-portlet";
 5
 6    // ** THIS FAILS **
 7    boolean hasProposalCreatePermission = permissionChecker.hasPermission(
 8            scopeGroupId, className,
 9            scopeGroupId, "PROPOSAL-CREATE");
10
11     // this works
12     boolean hasProposalViewPermission = permissionChecker.hasPermission(
13            scopeGroupId, Group.class.getName(), scopeGroupId,
14            ActionKeys.PERMISSIONS);
15%>


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
RE: Creating new actions and checking those actions in a JSP
June 28, 2012 3:13 AM
Answer

Luigi Molinaro

Rank: New Member

Posts: 13

Join Date: May 29, 2012

Recent Posts

I have the same problem. Have you solved?
Sameer Srivastava
RE: Creating new actions and checking those actions in a JSP
December 5, 2012 9:49 AM
Answer

Sameer Srivastava

Rank: New Member

Posts: 14

Join Date: August 22, 2012

Recent Posts

Hi guys,

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

Regards,

Sameer
C Endle
RE: Creating new actions and checking those actions in a JSP
December 6, 2012 5:30 AM
Answer

C Endle

Rank: New Member

Posts: 7

Join Date: October 3, 2011

Recent Posts

I have not resolved this issue yet.

Regards,
Cory
Jan Geißler
RE: Creating new actions and checking those actions in a JSP
December 6, 2012 5:37 AM
Answer

Jan Geißler

Rank: Expert

Posts: 354

Join Date: July 5, 2011

Recent Posts

You are Checking for a Resource Permission, not a portlet Permission.

However:
1
2boolean hasProposalCreatePermission = permissionChecker.hasPermission(
3            scopeGroupId, portletName,
4            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