Creating SearchContainer

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>

details.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"%>
<%@page import="java.util.List"%>
<%@page import="com.autoservice.model.AutoDetails"%>
<%@page import="com.autoservice.service.AutoDetailsLocalServiceUtil"%>
<%@page import="com.liferay.portal.kernel.util.ListUtil"%>
<%@page import="javax.portlet.PortletURL"%>

<liferay-portlet:renderURL varImpl="iteratorURL">
	<portlet:param name="mvcPath" value="/details.jsp" />
</liferay-portlet:renderURL>

<liferay-ui:search-container emptyResultsMessage="there-are-no-autodetails"
	headerNames="Year,Model,VIN,Manufacturer,userId"
	iteratorURL="<%=iteratorURL%>" delta="10" deltaConfigurable="true" >
	
	<liferay-ui:search-container-results>
		<%
		
			List<AutoDetails> autoDetailsList = AutoDetailsLocalServiceUtil.findAll();
					results = ListUtil.subList(autoDetailsList, searchContainer.getStart(), searchContainer.getEnd());
					searchContainer.setTotal(autoDetailsList.size());
					searchContainer.setResults(results);
		%>
	</liferay-ui:search-container-results>
	
	<liferay-ui:search-container-row className="AutoDetails"
		keyProperty="autoDetailId" modelVar="currentObjectAutoDetails"  >
		<liferay-ui:search-container-column-text name="Year"
			property="year" />
		<liferay-ui:search-container-column-text name="Model"
			property="model" />
		<liferay-ui:search-container-column-text name="VIN"
			property="VIN" />
			<liferay-ui:search-container-column-text name="Manufacturer"
			property="manufacturer" />
		<liferay-ui:search-container-column-text name="userId"
			property="userId" />		
	</liferay-ui:search-container-row>
	
	<liferay-ui:search-iterator searchContainer="<%=searchContainer%>" />
</liferay-ui:search-container>

AutoDetailsPortlet.java

package com.autodetails.portlet;

import com.autoservice.model.AutoDetails;
import com.autoservice.service.AutoDetailsLocalServiceUtil;
import com.liferay.counter.kernel.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.WebKeys;

import java.io.IOException;
import java.util.Date;

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;

/**
 * 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);
		try {
			AutoDetails autoDetails = AutoDetailsLocalServiceUtil
					.createAutoDetails(CounterLocalServiceUtil.increment());
			ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

			long userId = themeDisplay.getUserId();

			autoDetails.setUserId(userId);
			autoDetails.setUserName(themeDisplay.getUser().getScreenName());
			autoDetails.setCreateDate(new Date());
			autoDetails.setModifiedDate(new Date());

			String manufacturer = ParamUtil.getString(actionRequest, "manufacturer");
			autoDetails.setManufacturer(manufacturer);
			String year = ParamUtil.getString(actionRequest, "year");
			autoDetails.setYear(Integer.parseInt(year));
			String vin = ParamUtil.getString(actionRequest, "vin");
			autoDetails.setVIN(vin);
			String bodystyle = ParamUtil.getString(actionRequest, "bodystyle");
			autoDetails.setBodystyle(bodystyle);
			String model = ParamUtil.getString(actionRequest, "model");
			autoDetails.setModel(model);
			AutoDetailsLocalServiceUtil.addAutoDetails(autoDetails);
			System.out.println("---------------------SUCCESS-------------------------");
			actionResponse.setRenderParameter("mvcPath", "/details.jsp");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
Download Sourcecode : AUI_FORM_IN_LIFERAY7.zip

 

Leave a Reply

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