Liferay DXP : Creating a new Portlet

This is the code to create new portlet in Liferay 7 / Liferay DXP .

init.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %><%@
taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %><%@
taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %><%@
taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>

<liferay-theme:defineObjects />

<portlet:defineObjects />

view.jsp

<!--  Migrated to Liferay 7 / Liferay DXP by  Manish Kumar Jaiswal -->

<!--  ********Author Details******** -->
<!--  Manish Kumar Jaiswal -->
<!--  Email : Manish.kr.jaiswal@gmail.com -->
<!--  Cell No:+919990866537 -->
<!--  ********Author Details******** -->


<%@ include file="/init.jsp"%>

<portlet:actionURL name="autoDetailsSubmit" var="autoDetailsSubmit" />

<aui:form action="<%=autoDetailsSubmit%>" method="post"
name="autoDetailsSubmit">

	<!-- MANUFACTURER -->
	<aui:fieldset>
		<aui:select label="Manufacturer" name="manufacturer">
			<aui:option label="AUDI" />
			<aui:option label="BMW" />
			<aui:option label="GM" />
			<aui:option label="VOLVO" />
			<aui:option label="TATA" />
		</aui:select>
	</aui:fieldset>

	<!-- YEAR -->
	<aui:fieldset>
		<aui:select label="Year Of Manufactoring" name="year">
			<aui:option label="2011" />
			<aui:option label="2012" />
			<aui:option label="2013" />
			<aui:option label="2014" />
			<aui:option label="2015" />
		</aui:select>
	</aui:fieldset>


	<aui:input name="vin" label="VIN" />

	<aui:input name="bodystyle" label="Bodystyle" />
	<aui:input name="model" label="Model" />



	<aui:button class="btn btn-success" name="Submit" type="submit" />

</aui:form>

AutoDetailsPortlet.java

package com.autodetails.portlet;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.Portlet;
import javax.portlet.PortletException;
import javax.portlet.ProcessAction;

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

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

/**
 * Migrated to Liferay 7 / Liferay DXP by  Manish Kumar Jaiswal
 * 
 * --------Author Details---------
 * Name:   Manish Kumar Jaiswal
 * Email : Manish.kr.jaiswal@gmail.com
 * Cell No:+919990866537
 * --------Author Details---------
 * 
 */

@Component(immediate = true, property = { "com.liferay.portlet.display-category=category.sample",
		"com.liferay.portlet.instanceable=true", "javax.portlet.display-name=AutoDetails 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 AutoDetailsPortlet extends MVCPortlet {

	@ProcessAction(name = "autoDetailsSubmit")
	public void autoDetailsSubmit(ActionRequest actionRequest, ActionResponse actionResponse)
			throws IOException, PortletException {

		System.out.println(">>>>>>>>>>>>>>>>>>>>>Into autoDetailsSubmit");
		ParamUtil.print(actionRequest);
		
	}
}

Download Sourcecode :

 

Leave a Reply

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