view.jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<%@page import="javax.portlet.ActionResponse"%>
<%@ include file="/html/reg/init.jsp" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@page import="com.liferay.portal.model.Country"%>
<%@page import="com.liferay.portal.service.CountryServiceUtil"%>
<portlet:defineObjects />
<%
PortletURL formURL=renderResponse.createActionURL();
formURL.setParameter(ActionRequest.ACTION_NAME, RegConstants.ACTION_FORM );
%>
<aui:form name="fm" method="POST" action="<%=formURL.toString()%>">
<%-- <aui:input name="redirectURL" type="hidden"
value="<%=renderResponse.createRenderURL().toString()%>"/> --%>
<aui:input name="userName" label="User Name">
<aui:validator name="required"/>
</aui:input>
<aui:input name="email" label="Email Id">
<aui:validator name="required"/>
<aui:validator name="email"/>
</aui:input>
<aui:input name="dob" label="Date Of Birth" id="dob" value="" >
<aui:validator name="date"/>
</aui:input>
<aui:input name="contact" label="Contact No">
<aui:validator name="number"/>
<aui:validator name="minLength">10</aui:validator>
<aui:validator name="maxLength">10</aui:validator>
</aui:input>
<aui:select name="countryId"/>
<aui:select showEmptyOption="true" name="city" label="City">
<aui:option label="n1" value="n1"></aui:option>
<aui:option label="n2" value="n2"></aui:option>
</aui:select>
<%-- <aui:input type="file" name="uploadResume" size="75"/> --%>
<aui:button type="submit" value="Submit"/>
</aui:form>
<aui:script>
Liferay.Util.focusFormField(
document.<portlet:namespace/>fm.<portlet:namespace/>userName);
</aui:script>
<aui:script>
AUI().ready(function(A){
var frm=document.<portlet:namespace />fm;
var countries=frm.<portlet:namespace />countryId;
Liferay.Service(
'/country/get-countries',
{active:true},
function(obj){
for(var key in obj){
if(obj.hasOwnProperty(key)){
var name=obj[key].name;
var countryId=obj[key].countryId;
countries.options[key]=new Option(name,countryId);
}
}
}
);
});
</aui:script>
<%
PortletURL listRegsURL=renderResponse.createRenderURL();
listRegsURL.setParameter("jspPage","/html/reg/list.jsp");
%>
|
<a href="<%= listRegsURL.toString()%>">Show All Register Detail »</a>
init.jsp
<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%>
<%@taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@page import="javax.portlet.PortletURL" %>
<%@page import="javax.portlet.ActionRequest" %>
<%@page import="com.reg.RegConstants"%>
<%@page import="java.util.List"%>
<%@page import="com.slayer.model.REGForm"%>
<%@page import="com.slayer.service.REGFormLocalServiceUtil"%>
<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
//RegPortlet.java(action class)
package com.reg;
import com.liferay.util.bridges.mvc.MVCPortlet;
import java.io.File;
import java.io.IOException;
import java.sql.Date;
import java.util.List;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletRequest;
import javax.portlet.PortletURL;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.ServiceContextFactory;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portlet.PortletURLFactoryUtil;
import com.liferay.portlet.documentlibrary.model.DLFileEntry;
import com.liferay.portlet.documentlibrary.model.DLFolder;
import com.liferay.portlet.documentlibrary.service.DLFileEntryServiceUtil;
import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
import com.slayer.model.REGForm;
import com.slayer.model.impl.REGFormImpl;
import com.slayer.service.REGFormLocalServiceUtil;
/**
* Portlet implementation class RegPortlet
*/
public class RegPortlet extends MVCPortlet {
public void form(ActionRequest actionRequest,ActionResponse actionResponse)
throws IOException, PortletException{
String userName=ParamUtil.getString(actionRequest, "userName");
String email=ParamUtil.getString(actionRequest, "email");
String dob=ParamUtil.getString(actionRequest, "dob");
long contact=ParamUtil.getLong(actionRequest, "contact");
String city=ParamUtil.getString(actionRequest,"city");
//Boolean uploadResume=ParamUtil.getBoolean(actionRequest,"uploadResume");
System.out.println("InPuts Are==>"+userName+","+email+","+dob+","+contact+","+city);
REGFormLocalServiceUtil.insert(userName,email,dob,contact,city);
ThemeDisplay themeDisplay =
(ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
PortletConfig portletConfig =
(PortletConfig) actionRequest.getAttribute("javax.portlet.config");
String portletName = portletConfig.getPortletName();
PortletURL successPageURL = PortletURLFactoryUtil.create(
actionRequest,
portletName + "_WAR_" + portletName + "portlet",
themeDisplay.getPlid(),
PortletRequest.RENDER_PHASE);
successPageURL.setParameter("jspPage", RegConstants.PAGE_SUCCESS);
System.out.println("***********");
actionResponse.sendRedirect(successPageURL.toString());
System.out.println("hiiiiiii");
}
}
//RegConstants.java (Interface)
package com.reg;
public interface RegConstants {
static final String ACTION_FORM = "form";
static final String PAGE_SUCCESS = "/html/reg/success.jsp";
static final String PAGE_LIST="/html/reg/list.jsp";
}
service.xml
xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
<service-builder package-path="com.slayer">
<author>mohsin</author>
<namespace>REG</namespace>
<entity name="REGForm" local-service="true" remote-service="true">
<!-- PK fields -->
<column name="regId" type="long" primary="true" id-type="increment"/>
<!-- Audit fields -->
<column name="userName" type="String" />
<column name="email" type="String" />
<column name="dob" type="String" />
<column name="contact" type="long" />
<column name="city" type="String" />
<column name="createDate" type="Date" />
<!-- <column name="modifiedDate" type="Date" />
-->
<!-- Other fields -->
<!-- <column name="field1" type="String" />
<column name="field2" type="boolean" />
<column name="field3" type="int" />
<column name="field4" type="Date" />
<column name="field5" type="String" /> -->
<!-- Order -->
<!-- <order by="asc">
<order-column name="field1" />
</order>
Finder methods
<finder name="Field2" return-type="Collection">
<finder-column name="field2" />
</finder>
--> </entity>
</service-builder>
// REGFormLocalServiceImpl.java
package com.slayer.service.impl;
import java.util.Date;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.service.ServiceContext;
import com.slayer.model.REGForm;
import com.slayer.model.impl.REGFormImpl;
import com.slayer.service.base.REGFormLocalServiceBaseImpl;
/**
* The implementation of the r e g form local service.
*
* <p>
* All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link com.slayer.service.REGFormLocalService} interface.
*
* <p>
* This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
* </p>
*
* @author mohsin
* @see com.slayer.service.base.REGFormLocalServiceBaseImpl
* @see com.slayer.service.REGFormLocalServiceUtil
*/
public class REGFormLocalServiceImpl extends REGFormLocalServiceBaseImpl {
public REGForm insert(String userName,String email,String dob,long contact,String city){
REGForm regForm =new REGFormImpl();
regForm.setUserName(userName);
regForm.setEmail(email);
regForm.setDob(dob);
regForm.setContact(contact);
regForm.setCity(city);
regForm.setCreateDate(new Date());
//regForm.setUploadResume(uploadResume);
try{
regForm=addREGForm(regForm);
}catch(SystemException e){
e.printStackTrace();
}
return regForm;
}
}
list.jsp
<%@include file="/html/reg/init.jsp"%>
<%@page import="com.liferay.portal.kernel.util.ListUtil" %>
<portlet:defineObjects/>
<h1>List of Registered Member</h1>
<%
List<REGForm>regs = REGFormLocalServiceUtil.getREGForms(0,-1);
PortletURL iteratorURL = renderResponse.createRenderURL();
iteratorURL.setParameter("jspPage",RegConstants.PAGE_LIST);
%>
<liferay-ui:search-container delta="4"
emptyResultsMessage="Sorry there are no item to display."
iteratorURL="<%=iteratorURL%>">
<liferay-ui:search-container-results
total="<%=regs.size() %>"
results="<%= ListUtil.subList(regs,
searchContainer.getStart(),
searchContainer.getEnd()) %>"/>
<liferay-ui:search-container-row modelVar="reg"
className="REGForm">
<liferay-ui:search-container-column-text
name="User Name" property="userName"/>
<liferay-ui:search-container-column-text
name="Email Id" property="email"/>
<liferay-ui:search-container-column-text
name="DOB" property="dob"/>
<liferay-ui:search-container-column-text
name="Contact No" property="contact"/>
<liferay-ui:search-container-column-text
name="City" property="city"/>
<liferay-ui:search-container-column-text
name="Reg Date" property="createDate"/>
</liferay-ui:search-container-row>
<liferay-ui:search-iterator
searchContainer="<%=searchContainer%>"/>
</liferay-ui:search-container>
<br><a href="<portlet:renderURL/>"> « Go Back </a>
*********Adding delete link in each row*********
list.jsp
Put this code in scriptlet
PortletURL deleteRegURL=renderResponse.createActionURL();
deleteRegURL.setParameter(ActionRequest.ACTION_NAME,
RegConstants.ACTION_DELETE_REG);
deleteRegURL.setParameter("redirectURL",iteratorURL.toString());
Put this code before </liferay-ui:search-container-row>
<%deleteRegURL.setParameter("regId",Long.toString(reg.getRegId()));%>
<liferay-ui:search-container-column-text name="Delete"
href="<%=deleteRegURL.toString() %>" value="delete"/>
//RegPortlet.java(action class) add delete method in action class
public void deleteReg(ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException,PortletException{
long regId=ParamUtil.getLong(actionRequest, "regId");
if(regId > 01){ //valid regId
try{
REGFormLocalServiceUtil.deleteREGForm(regId);
}catch(PortalException e){
e.printStackTrace();
}catch(SystemException e){
e.printStackTrace();
}
}
//gracefully redirecting to the list view
String redirectURL=ParamUtil.getString(actionRequest,"redirectURL");
actionResponse.sendRedirect(redirectURL);
}
//RegConstants.java (Interface)
static final String ACTION_DELETE_REG="deleteReg";
Adding Actions on in each row