• Adding Portlet To Product Menu In Liferay 7 DXP

    Adding Portlet To Product Menu In Liferay 7 DXP

    Adding Portlet To Product Menu In Liferay 7 DXP, In Earlier versions of liferay Before Liferay 7 we used to mention the control panel category in liferay-portlet.xml, In Liferay 7 DXP Portlet can be added to Product menu by extending  PanelApp Service

    Environment
    Liferay IDE 3.1.2 GA3
    Liferay CE/EE Portal Tomcat 7 GA4
    JDK 8
    MySql 5.7

    In Liferay 7 DXP The Layout of the Portal Have Been Changed, The New Layout of the Liferay 7 DXP Portal is Shown Below







    Step 1 : Create A Portlet

    Create A Portlet Which needs to added to the Product Menu
    In My Case I have Created  a Portlet Named "Product Admin Portlet", make the category of this portlet to hidden using "com.liferay.portlet.display-category=category.hidden"
    The Complete Portlet Class of the portlet is shown below.
    package com.liferaystack.admin.panel.app.portlet;
    
    import com.liferaystack.admin.panel.app.constants.ProductAdminPortletKeys;
    import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
    import javax.portlet.Portlet;
    import org.osgi.service.component.annotations.Component;
    
    /**
     * @author Syed Ali
     */
    
    @Component(
     immediate = true,
     property = {
      "com.liferay.portlet.display-category=category.hidden",
      "com.liferay.portlet.instanceable=true",
      "javax.portlet.display-name=Product Admin Portlet",
      "javax.portlet.init-param.template-path=/",
      "javax.portlet.init-param.view-template=/view.jsp",
      "javax.portlet.name=" + ProductAdminPortletKeys.ProductAdmin,
      "javax.portlet.resource-bundle=content.Language",
      "javax.portlet.security-role-ref=power-user,user"
     },
     service = Portlet.class
    )
    public class ProductAdminPortlet extends MVCPortlet {
    }
    


    Step 2 : Add Dependency

    Add the below Gradle Dependency to the Portlet, This Dependency is mandatory.
    compileOnly group: "com.liferay", name: "com.liferay.application.list.api", version: "2.0.0"
    to your build.gradle


    Step 3 : Create ProductAdminPanelApp Component Class

    Create a Class named ProductAdminPanelApp, this class must extend the BasePanelApp Class, implement the methods of super class as shown below and declare it as a service using service = PanelApp.class

    @Override
    public String getPortletId() {
     return ProductAdminPortletKeys.ProductAdmin;
    }
    
        @Override
        @Reference(target = "(javax.portlet.name=" + ProductAdminPortletKeys.ProductAdmin + ")",unbind = "-")
        public void setPortlet(Portlet portlet) {
            super.setPortlet(portlet);
        }
    

    The Complete ProductAdminPanelApp Will be

    package com.liferaystack.admin.panel.app.portlet;
    
    import com.liferay.application.list.BasePanelApp;
    import com.liferay.application.list.PanelApp;
    import com.liferay.application.list.constants.PanelCategoryKeys;
    import com.liferay.portal.kernel.model.Portlet;
    import com.liferaystack.admin.panel.app.constants.ProductAdminPortletKeys;
    
    import org.osgi.service.component.annotations.Component;
    import org.osgi.service.component.annotations.Reference;
    
    /**
     * @author Syed Ali
     */
    
    @Component(
         immediate = true,
         property = {
             "panel.app.order:Integer=100",
             "panel.category.key=" + PanelCategoryKeys.CONTROL_PANEL_USERS
         },
        service = PanelApp.class
    )
    public class ProductAdminPanelApp extends BasePanelApp {
    
        @Override
        public String getPortletId() {
     return ProductAdminPortletKeys.ProductAdmin;
        }
    
        @Override
        @Reference(target = "(javax.portlet.name=" + ProductAdminPortletKeys.ProductAdmin + ")",unbind = "-")
        public void setPortlet(Portlet portlet) {
            super.setPortlet(portlet);
        }
    }
    

    You are done just deploy the portlet. After Deploying the created portlet you can see your portlet under Users Category Of Control Panel Section of the Product Menu. as shown below.



    Source Code


  • 7 comments:

    1. Awesome Article . Really helpful . I have a doubt on this . when I click the Product Admin Portlet , in the Product Menu , Nothing happened. it is showing empty page . How to show the content , when click the product admin portlet in the product menu

      ReplyDelete
    2. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely helpful for me. Eyyaa

      ReplyDelete
    3. I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us. www.yoursafetyspy.com

      ReplyDelete
    4. Here’s a tip for new people in the business world - brand naming businesses like this are key to creating great product names and taglines. You need them if you want to make it somewhere in the market!

      ReplyDelete
    5. When your website or blog goes live for the first time, it is exciting. That is until you realize no one but you and your. outdoor screen projector

      ReplyDelete
    6. Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!Thanks best bath towels

      ReplyDelete
    7. If you are looking for more information about flat rate locksmith Las Vegas check that right away. packaging material suppliers Malaysia

      ReplyDelete