Foros de discusión

How to define a custom action for a custom portlet

Lior Hadaya, modificado hace 11 años.

How to define a custom action for a custom portlet

Regular Member Mensajes: 138 Fecha de incorporación: 24/01/12 Mensajes recientes
Hello,
I'm using Liferay 6.1.10 EE and I am developing my own portlet.
I want to add my own action to the portlet, and I'm having some problems.

I was able to define the resource action xml just fine I think, since when I go the the portlet's Permissions tab, I do see my new action - it is called "Do Something".
This is how my xml looks like:
<!--?xml version="1.0"?-->

<resource-action-mapping>
    <portlet-resource>
        <portlet-name>helloWorld</portlet-name>
        <permissions>
            <supports>
                <action-key>DO_SOMETHING</action-key>      	
                <action-key>ADD_TO_PAGE</action-key>
                <action-key>CONFIGURATION</action-key>
                <action-key>VIEW</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>


In the control panel I am also able to define a role with permission to "Do Something" on my portlet - which means I must be doing something right, right?

In my JSP I tried to use the hasPermission method to see if the user has permission or not.. I also checked the Configuration action as well to compare:

&lt;%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %&gt; 
&lt;%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %&gt; 
&lt;%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%&gt;

<portlet:defineobjects />
<liferay-theme:defineobjects />
                &lt;%
		String portletId= portletDisplay.getId();
		if (permissionChecker.hasPermission( 0, portletName, portletId, "DO_SOMETHING")) { %&gt;
			<a href="">Do Something!</a>
		&lt;% } else {%&gt;
			No permission to do something
		&lt;% } %&gt;

               &lt;%
		if (permissionChecker.hasPermission( 0, portletName, portletId, "CONFIGURATION")) { %&gt;
			Configuration permission exist
		&lt;% } else {%&gt;
			No permission for configuration
		&lt;% } %&gt;


The configuration action check works well, returns true when I'm signed in as administrator and false when I log out.
The hasPermission check always returns false even when I log in with a user that has a role assigned to it which has the "do something" permission.

In the log I see errors for both actions:

10:30:21,645 ERROR [AdvancedPermissionChecker:955] com.liferay.portal.NoSuchResourceActionException: helloWorld#DO_SOMETHING
com.liferay.portal.NoSuchResourceActionException: helloWorld#DO_SOMETHING

0:30:21,650 ERROR [AdvancedPermissionChecker:627] com.liferay.portal.NoSuchResourceActionException: helloworld#configuration
com.liferay.portal.NoSuchResourceActionException: helloworld#configuration


Can someone please assist? what am I missing?

Thanks,

Lior
Lior Hadaya, modificado hace 11 años.

RE: How to define a custom action for a custom portlet

Regular Member Mensajes: 138 Fecha de incorporación: 24/01/12 Mensajes recientes
Anyone?

Just to clarify, I see the execption about the configuration permission only when I log in with the non-administrator user:
 com.liferay.portal.NoSuchResourceActionException: helloworld#configuration
com.liferay.portal.NoSuchResourceActionException: helloworld#configuration


The other exception happens for both the administrator and non-administrator user:
com.liferay.portal.NoSuchResourceActionException: helloWorld#DO_SOMETHING
com.liferay.portal.NoSuchResourceActionException: helloWorld#DO_SOMETHING


Please advise,
Thanks
thumbnail
Robin Martin, modificado hace 11 años.

RE: How to define a custom action for a custom portlet

New Member Mensaje: 1 Fecha de incorporación: 26/07/12 Mensajes recientes
Hi guys.

Liferay 6.1.0 CE (tried it on 6.0.9 CE as well)
We are in the same boat, having lost a few days trying to get this working - without any joy.
We have custom roles and custom actions, but cannot seem to determine the permissions from the code using hasPermission.
Checking permissions from Velocity macro works okay, BTW.

Did you manage to get things working at all ??

Robin.