Tuesday 29 August 2017

Create MVC Portlet in Liferay 7 using LiferayIDE

Create MVC Portlet in Liferay 7 using LiferayIDE

Liferay 7 has adopted OSGI standards.In OSGI everything we create is a module.For more information on OSGI visit my previous blog onOSGI.



Create MVC Module using Liferay IDE.


GoTo New→File click on Liferay Module Project.


  • Enter Project Name and select mvcportlet as project template.
  • Click Next and enter component class name and package name then click on finished.




Generated module will be inside module folder of liferay workspace.

Generated Portlet Class

  • Based on input provided generated portlet class is 


ProductRegistrationPortlet.java


package com.liferay.product.portlet;


import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;


import javax.portlet.Portlet;


import org.osgi.service.component.annotations.Component;


@Component(

immediate = true,
property = {
"com.liferay.portlet.display-category=category.sample",
"com.liferay.portlet.instanceable=true",
"javax.portlet.display-name=ProductRegistration Portlet",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user"
},
service = Portlet.class
)
public class ProductRegistrationPortlet extends MVCPortlet {

}

  • Here property{

          
         }
tag is used to specify properties that are previously specified in portlet.xml and  liferay-portlet.xml

  • For more detail on mapping of portlet XML descriptor values to OSGi service properties click here.
  • Now we can have to build and deploy generated mvc portlet using gradle tasks as shown in fig.



  • Click on build this will generate jar file of porltet module.On clicking deploy this jar will be deployed and your portlet will be available.
  • Note you must have to set liferay.workspace.home.dirand liferay.workspace.modules.default.repository.enabled     properties in gradle.properties (for more information click here)

No comments:

Post a Comment