Liferay DXP ActionCommand Hook


Liferay DXP ActionCommand Hook

Liferay DXP ActionCommand Hook tutorial will drive you on customizing liferay portlet actions such as user authentication action,edit journal article action, edit  blog action etc.

Installations:

Liferay DXP Portlet Actions Customizations:

We will create simple Activator project and will create action command component later.

    • In Liferay Eclipse IDE, Click on File  -> New -> Liferay Module Project:Select activator from project template
    • In this wizard just give package name and some class name. Package name will be used as Bundle-Symbolic name. so give some proper name
    • Delete the Activator class that created and remove the Bundle-Activator reference from bnd.bnd file
    • bnd.bnd file will be :
      • Bundle-Name: hook-portlet-action
        Bundle-SymbolicName: org.javasavvy.hook.portlet.actions
        Bundle-Version: 1.0.0
    • update build.gradle file and refresh the Gradle dependencies. Right click on the module project -> Gradle -> Refresh Gradle Project to load the dependencies
      1. dependencies {
         compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
         compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.0.0"
         compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
         compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
         compileOnly group: "jstl", name: "jstl", version: "1.2"
         compileOnly group: "org.osgi", name: "org.osgi.compendium", version: "5.0.0"
         compile group: "org.osgi", name:"org.osgi.service.component.annotations", version:"1.3.0"
        }
    • Create Class with “CustomLoginActionCommand” in the package :org.javasavvy.hook.porltet.actions
    • For portlet action commands:
      • ActionCommand class need to extend BaseMVCActionCommand
      • RenderCommand class need to implement MVCRenderCommand
      • @Component would be:
      • @Component(
         immediate = true,
         property = {
         "javax.portlet.name=com_liferay_login_web_portlet_LoginPortlet",
         "mvc.command.name=/login/login",
         "service.ranking:Integer=100"
         },
         service = MVCActionCommand.class
         )
    • CustomLoginActionCommand.java is:
      1. package org.javasavvy.hook.portlet.actions;
        
        import javax.portlet.ActionRequest;
        import javax.portlet.ActionResponse;
        
        import org.osgi.service.component.annotations.Component;
        import org.osgi.service.component.annotations.Reference;
        
        import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand;
        import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand;
        
        @Component(
         immediate = true,
         property = {
         "javax.portlet.name=com_liferay_login_web_portlet_LoginPortlet",
         "mvc.command.name=/login/login",
         "service.ranking:Integer=100"
         },
         service = MVCActionCommand.class
         )
        public class CustomLoginActionCommand extends BaseMVCActionCommand {
        
         @Override
         protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
         
         System.out.println("executiong login authentication");
         
         mvcActionCommand.processAction(actionRequest, actionResponse);
         
         }
         
         /*
         * You still execute original logic
         */
         @Reference(target = "(&(mvc.command.name=/login/login)(javax.portlet.name=com_liferay_login_web_portlet_LoginPortlet))")
         protected MVCActionCommand mvcActionCommand;
        
        }
    • Now deploy the bundle and you can see the bundle started message in the logs

 

Click here to download Liferay DXP Custom Login Action hook

3 thoughts on “Liferay DXP ActionCommand Hook”
  1. How to check if login is successful or not? If not successful, how do I customize the error message? If successful, how do I redirect it to a specific page or maybe landing page? Thank you.

  2. Hi All,

    In Liferay document library when we update the permissions of folder “A” . Folder A subfolders -> subfolders upto end folder also needs to update with same permissions.
    In 6.2 i did it using of structuts Action path(EditPermissionsAction action class hook implemented) and working fine, but now i need to implement same thing in liferay 7 in liferay 7 they implemented permissions in portlet-configuration-web MVC portlet(PortletConfigurationPortlet ) But in hook how we can implement it?
    The EditPermissionsAction class Extented MVCportlet and in this class updateRolePermissions is a action Method.
    But In jsp page they are not using the MVCActionCommand

    <portlet:param name="tabs2" value="” />
    <portlet:param name="cur" value="” />
    <portlet:param name="delta" value="” />
    <portlet:param name="returnToFullPageURL" value="” />
    <portlet:param name="portletConfiguration" value="” />
    <portlet:param name="portletResource" value="” />
    <portlet:param name="modelResource" value="” />
    <portlet:param name="modelResourceDescription" value="” />
    <portlet:param name="resourceGroupId" value="” />
    <portlet:param name="resourcePrimKey" value="” />
    <portlet:param name="roleTypes" value="” />

    Using of ActionCommandHook we can implement it?. if yes Please give me basic idea how to implement?

    Please let me know if any one knows.

Leave a Reply

Your email address will not be published. Required fields are marked *