A Simple Registration Form

I have developed a simple registration form by using liferay 6.1 version.Also we can develope other versions.

It is my first post.from this post we can know how to build servicebuilder and table creation in mysql.

Registrationform1Portlet.java:

package com.registrationform1;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.model.Region;
import com.liferay.portal.service.RegionServiceUtil;
/**
 * Portlet implementation class Registrationform1Portlet
 */
public class Registrationform1Portlet extends MVCPortlet {
    private static Log log = LogFactoryUtil.getLog(Registrationform1Portlet.class);
    //ajax call serve method
    
    @Override
    public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
    throws IOException, PortletException {
        long countryIdLong = ParamUtil.getLong(resourceRequest,"countryIdVal");
        log.info("countryIdLong: "+countryIdLong);
        List<Region> regions = null;
        try {
            regions = RegionServiceUtil.getRegions(countryIdLong);
        }
        catch (SystemException e) {
            e.printStackTrace();
        }
        log.info("regions: "+regions);
        for(Region region : regions){
            log.info("name: "+region.getName());
            log.info("regionId: "+region.getRegionId());
        }
        //PrintWriter pw = null;
        //pw = resourceResponse.getWriter();
        //pw.print("hello world");
    }
 
    
    public void addData(ActionRequest actionRequest, ActionResponse actionResponse)
    throws IOException, PortletException
    {
        String firstName = ParamUtil.getString(actionRequest, "firstName");
        String lastName = ParamUtil.getString(actionRequest, "lastName");
        String fatherName = ParamUtil.getString(actionRequest, "fatherName");
        String motherName = ParamUtil.getString(actionRequest, "motherName");
        String dateofbirht = ParamUtil.getString(actionRequest, "dateofbirht");
        String Age = ParamUtil.getString(actionRequest, "Age");
        String gender = ParamUtil.getString(actionRequest, "gender");
        String Country = ParamUtil.getString(actionRequest, "Country");
        String State = ParamUtil.getString(actionRequest, "State");
        String City = ParamUtil.getString(actionRequest, "City");
        String Nationality = ParamUtil.getString(actionRequest, "Nationality");
        String PassportNumber = ParamUtil.getString(actionRequest, "PassportNumber");
        String IdcardNumber = ParamUtil.getString(actionRequest, "IdcardNumber");
        String PhoneNumber = ParamUtil.getString(actionRequest, "PhoneNumber");
        String EmailAddress = ParamUtil.getString(actionRequest, "EmailAddress");
        
        System.out.println("First Name"+firstName);
        System.out.println("Last Name"+lastName);
        System.out.println("Father Name"+fatherName);
        System.out.println("mother Name"+motherName);
        System.out.println("Date of Birth"+dateofbirht);
        System.out.println("Age is"+Age);
        System.out.println("Gendeer"+gender);
        System.out.println("Country Name"+Country);
        System.out.println("State name"+State);
        System.out.println("City Name"+City);
        System.out.println("Nationality"+Nationality);
        System.out.println("PassportNumber"+PassportNumber);
        System.out.println("IdcardNumber"+IdcardNumber);
        System.out.println("PhoneNumber"+PhoneNumber);
        System.out.println("EmailAddress"+EmailAddress);
        
        
    }

}

view.jsp

<%@page import="com.liferay.portal.model.Country"%>
<%@page import="com.liferay.portal.service.CountryServiceUtil"%>
<%@ include file="/html/registrationform1/init.jsp" %>
<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>

<%@page import="com.liferay.portal.service.CountryServiceUtil"%>

<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>

<portlet:actionURL var="addDataURL" name="addData"/>

<portlet:resourceURL var="countryRegionURL" />

<h1><b><font color="blue"> Registration Form! </font></b></h1>

<form method="POST" action="<%= addDataURL %>" >
<%
    List<Country> countrlyList = CountryServiceUtil.getCountries();
    
%>

<table class="lineHight">
     <tr>
        <td class="columnWidth"><b>First Name:</b></td>
        <td>  
            <input type="text" name="firstName" id="firstName" />
        </td>
    </tr>
    <tr>
        <td  class="columnWidth"><b>Last Name:</b></td>    
        <td><input type="text" name="lastName" id="lastName" /></td>
    </tr>
    <tr>
        <td class="columnWidth"><b>Father Name:</b></td>
        <td><input type="text" name="fatherName"  id="fatherName" /></td>
    </tr>

    <tr>
        <td class="columnWidth"><b>Mother Name:</b></td>    
        <td><input type="text" name="motherName" id="motherName" /></td>
    </tr>
    
    <tr>
        <td class="columnWidth"><b>Date Of Birth:</b> </td>
        <td><input type="date" id="dateofbirht" name="dateofbirth" required"/ ></td>
    </tr>
    <tr>
        <td class="columnWidth"><b>Age:</b></td>
        <td><input type="number" name="Age" size="5" min="0" max="150" step="1" id="Age"  /></td>
    </tr>
    
    <tr>
        <td class="columnWidth"><label for="gender"><b>Gender:</b></label></td>
        <td><input type="radio" name="gender" value="0">Male</input></td>
        <td><input type="radio" name="gender" value="1">Female</input></td>
    </tr>
    
    <tr>
        <td class="columnWidth"><b>Country:</b></td>
      <td>
          <select onChange="javascript:selectRegionList(this);" style="width: 147px;">
            <option value="-1" >select country</option>
              <%
                for(Country country : countrlyList){
                    %>
                        <option value="<%= country.getCountryId() %>"><%= country.getName() %></option>
                    <%
                }
              %>
          </select>
      </td>
      
      <!-- drop down list for selecting states -->
    <tr>
        <td class="columnWidth"><b>State:</b></td>
        
        <td>
            <select name="stateList" id="stateList" style="width: 147px;">
                <option value="-1">Select State</option>
            </select>
        </td>
        </tr>   
    <tr>
        <td class="columnWidth"><b>City:</b></td>
        <td>
        <select name ="cityList" id="cityList" style =" width:147px;">
        <option value ="-1">SelectCity</option>
        </select>
        </td> </tr>
        <%-- <portlet:resourceURL id="selectCity" var="selectCity" >
     <input type="text" name="City"   onclick="getRegions();" /> <!-- value="SelectState" -->
     <option value="-1" >Select City</option>
    </portlet:resourceURL></td> --%>
       
    
    <tr>
        <td class="columnWidth"><b>Nationolity:</b></td>
        <td><input type="text" name="Netionolity" label="Netionolity" /></td>
    </tr>
      
    <tr>
        <td class="columnWidth"><b>*Passport No:</b></td>
        <td><input type="text" name="PassportNumber"  id="PassportNumber" min="8" max="10"/></td>
    </tr>
    <tr>
        <td class="columnWidth"><b>*IdCard No:</b></td>
        <td><input type="text" name="IdCardNumber" id="IdCardNumber"/ ></td>
    </tr>
    <tr>
        <td class="columnWidth"><b>*Phone No:</b></td>
        <td><input type="text" name="PhoneNumber " id="PhoneNumber" maxRange='10'/></td>
    </tr>
    <tr>
        <td class="columnWidth"><b>Email Id:<b/></td>
        <td><input type="Email" name="Email" style="width: 145px;"  placeholder="Enter a valid email id" id="Email"/></td>
    </tr>
    
    <tr>
        <td class="columnWidth"><input type="submit"  value="submit" /></td>
    </tr>
    </table>
</form>

 <script type="text/javascript">
 
 $(function() {
     $( "#dateofbirht" ).datepicker({
           dateFormat: "dd/mm/yy",
     });
});
   /* jQuery(document).ready(
     function() {
       jQuery('#<portlet:namespace/>dateOfBirth').datepicker();
     }
   ); */

 jQuery("#lastName,#firstName,#fatherName,#motherName").keypress(function(event){
    var ew = event.which;
    if(48 <= ew && ew <= 57)
        return false;
    if(65 <= ew && ew <= 90)
        return true;
    if(97 <= ew && ew <= 122)
        return true;        
    return false;
});

jQuery("#dateOfBirth,#State").keypress(function(event){
    var ew = event.which;
    if(45 <= ew && ew <= 58)
        return true;
    if(65 <= ew && ew <= 90)
        return true;
    if(97 <= ew && ew <= 122)
        return true;        
    return false;
});

jQuery("#Age,#PhoneNumber").keypress(function(event){
    var ew = event.which;
    if(48 <= ew && ew <= 57)
        return true;        
    return false;
});

jQuery("#PassportNumber,#IdCardNumber").keypress(function(event){
    var ew = event.which;    
    if(48 <= ew && ew <= 57)
        return true;
    if(65 <= ew && ew <= 90)
        return true;
    if(97 <= ew && ew <= 122)
        return true;        
    return false;
});

//for selecting country dropdown list
function selectRegionList(object)
{
    //alert("country id: "+object.value);
    var countryId = object.value;
    
    if(countryId=="-1"){
        alert("please select country from list");
    }
    else{
        jQuery.ajax({
           type: 'POST',
           url:  "<%= countryRegionURL %>",
           data: {
               countryIdVal: countryId
           },
           error: function()
             {
               alert("AJAXError");
             },
              success: function(data){
                 alert("success function");
                 var stateListObject = document.getElementById("stateList");
                 for(var i=0 ; i<10 ; i++){
                     var optn = document.createElement("OPTION");
                     optn.text = "option"+i;
                     optn.value = i;
                     stateListObject.options.add(optn);
                  }
                var cityListObject = document.getElementById("cityList");
                  for(var i=0 ; i<15 ; i++)
                     {
                     var optn = document.createElement("option");
                     optn.text = "option"+i;
                     optn.value = i;
                     cityListObject.options.add(optn);
                     }
            }
           });
    }//else
}//selectRegionList

function selectState(id){
                 var country = jQuery('#<portlet:namespace />location').val();
                 var select = null;
                 var regionArray = [];
                 var regionSubArray = [];
                 
}    
        
    
</script>

<style>
.columnWidth{
    width:90px;
}
body {
  line-height:3.0;
}
</style>

<!-- //Ajax call to States -->

<script type="text/javascript">
<%-- function getRegions(){              
             jQuery.ajax({
                    type: "POST",
                    url: "<%= selectState.toString() %>",
                   error: function()
                     {
                       alert("AJAXError");
                     },
                   success: function(data){
                        alert(data);
                         }
             
            });
        } --%>
       /*  
        String strJSON = "stateList"; // your string goes here
        JSONArray jArray = (JSONArray) new JSONTokener(strJSON).nextValue();
        // once you get the array, you may check items like
        JSONOBject jObject = jArray.getJSONObject(1); */

        
</script>


    init.jsp

<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<%@ 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/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>

<liferay-theme:defineObjects />
<portlet:defineObjects />

<%@page import="java.util.List"%>
<%@page import="javax.portlet.ActionResponse"%>

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.registrationform1" auto-namespace-tables="false">
    <author>zameer</author>
    <namespace>Reg</namespace>

    <entity name="Registration" local-service="true" remote-service="false">

        <!-- PK fields -->

        <column name="RegistrationId" type="long" primary="true" id-type="increment"/>

        <!-- Audit fields -->

        <column name="firstName" type="String" />
        <column name="lastName" type="String" />
        <column name="fatherName" type="String" />
        <column name="motherName" type="String" />
        <column name="dateofbirth" type="Date" />
        <column name="Age" type="int" />
        <column name="gender" type="String" />
        <column name="Country" type="String" />
        <column name="State" type="String" />
        <column name="City" type="String" />
        <column name="Nationality" type="String" />
        <column name="PassportNumber" type="long" />
        <column name="IdcardNumber" type="long" />
        <column name="PhoneNumber" type="int" />
        <column name="EmailAddress" type="String"/>
        
    </entity>
</service-builder>