Custom portlet into control panel in Liferay 7.2

 



1. Create MVC portlet :

  1. Go to Liferay workspace project  modules  new.
  2. Select other  Liferay  Liferay Module Project and click on “Next”.
  3. Enter the project name.
  4. Select “Project Template Name” as “mvc-portlet” and click on “Next”.
  5. Enter a Package name and click on “Finish”. The necessary file structure for the MVC module will get created as below.

Replace the property with this code in your portlet class



  	package com.themeray.student.portlet;
	import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
    import com.themeray.student.constants.StudentPortletKeys;

    import javax.portlet.Portlet;

    import org.osgi.service.component.annotations.Component;
    @Component(
        immediate = true,
        property = {
            "com.liferay.portlet.display-category=category.hidden",
            "com.liferay.portlet.instanceable=true",
            "javax.portlet.display-name=Student Portlet",
            "javax.portlet.init-param.template-path=/",
            "javax.portlet.init-param.view-template=/view.jsp",
            "javax.portlet.name=" + StudentPortletKeys.STUDENT,
            "javax.portlet.resource-bundle=content.Language",
            "javax.portlet.security-role-ref=power-user,user",
        },
        service = Portlet.class
    )
    public class StudentPortlet extends MVCPortlet {

    }
  

2. Implement your constants class :

Add below code in your constants class.



    package com.themeray.student.constants;
    public class StudentPortletKeys {

        public static final String STUDENT =
            "com_themeray_student_StudentPortlet";

    }
    

3. Add Dependency : 

Add below line in "build.gradle" file


  compileOnly group: "com.liferay",name:"com.liferay.application.list.api"
  

4. Create your panel app component class

This class must extend the BasePanelApp Class and declare it as a service using service = PanelApp.class.

Add new class named StudentPanelApp


package com.themeray.student.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.themeray.student.constants.StudentPortletKeys;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

@Component(
	    immediate = true,
	    property = {
	        "panel.app.order:Integer=0",
	        "panel.category.key=" + PanelCategoryKeys.CONTROL_PANEL_USERS
	    },
	 
	    service = PanelApp.class)
	 
public class StudentPanelApp extends BasePanelApp {
 
    @Override
    public String getPortletId() {
        return StudentPortletKeys.STUDENT;
    }
 
    @Override
    @Reference(target = "(javax.portlet.name=" + StudentPortletKeys.STUDENT + ")", unbind = "-")
    public void setPortlet(Portlet portlet) {
        super.setPortlet(portlet);
    }
}


Lets understand following

panel.category.key” defines the category which is “control_panel.users” in our case. So our Student portlet will be added under “Users” section in control panel.

panel.app.order” defines the portlet position in the portlet list under “Users” section in control panel.

5. Deploy your module : 

 


0 comments: