Thursday, 16 June 2016

liferay user related tables

If we create User in Liferay the following tables will effect in DB
                  
        Contact_                          
         User_                               
         Users_Roles                    

       The above three  tables will effect in Data Base once if we create User .
       
         Along with these options we have some more options for user.

             Table Name                            Options for  User if we go to control panel

             Address                                                       Addresses

              Phone                                                         Phone Numbers

             Website                                                       Websites
            
             EmailAddress                                             Additional Email Addresses

             Contact_                                                      Social Network
            (facebookSn,twitterSn,mySpaceSn)

             Contact_                                                      sms
            (smsSn)

             User_                                                           openId
           (openId)

            AnnouncementsDelivery                             Announcements

             User_                                                           DisplaySetting
           (languageId, timeZoneId,greeting) 

             User_                                                           Comments
           (comments)

For Custom fields we have tables like ExpandoColumn,  ExpandoRow,  ExpandoTable and ExpandoValue.
Here if we have already custom fields we can give the values for those fields and save

Key Point : At what time table will create in liferay when we are using liferay service builder???

Once if we build the services all classes and interfaces will create but after deploying the portlet only the related  table will create in DataBase

Monday, 9 May 2016

Embedding custom portlet in Webcontent liferay

Create Web content and click on source.
Enter the below line

<p>
       <runtime-portlet instance="4433" name="portlet_name" querystring=""> </runtime-portlet>
</p>

how to get name---->Go to control panel---->Plugins Configuration---->copy plugin id and paste in the above line mentioned as name=" "

For Example :

<p>
       <runtime-portlet instance="4433" name="116" querystring=""> </runtime-portlet>
</p>


For Out of the box portlet Ids Please check in the below link

 Out of the box portlets

116 (Out of the box portlet Id)--------> Activities

Key Points : 
     If we want to generate a finder for primary key in liferay  service builder the return type should be an entity if return type is collection it will throw an error in persistance and util.java with error as Duplicate parameter columnName.

Monday, 21 September 2015

Liferay AUI validator example

        Liferay AUI Validations Using Custom Patterns

<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
<%@ 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/ui" prefix="liferay-ui"%>
<%@page import="javax.portlet.PortletURL"%>
<portlet:defineObjects />
<portlet:actionURL name="saveEmployee" var="saveEmployeeURL">
</portlet:actionURL>
<aui:form action="<%=saveEmployeeURL%>" method="POST"
       name="saveEmployeeForm" inlineLabels="true">
       <aui:field-wrapper>
              <aui:column columnWidth="15">
                     <label>Employee Name :<span style="color: red;"> *</span></label>
              </aui:column>
              <aui:column columnWidth="35">
                     <aui:input name="employeeName" type="text" label=""
                           inlineLabel="true">
                           <aui:validator name="required"></aui:validator>
                           <aui:validator name="custom" errorMessage="Name is Mandatory">
                            function (val, fieldNode, ruleValue)
                         {
                           var result = true;
                            if(val.length==0)
                             {
result=false;
                              }
                           return result;
                        }
                           </aui:validator>
                           <aui:validator name="custom"            
                                  errorMessage="Only Alphabets are allowed">
                                    function (val, fieldNode, ruleValue)
                                       {
                                           var result = true;
                                           var pattern=/[^a-z|^A-Z|^\s]/;
                                          var check = val.match(pattern);
                                          if(check!=null)
                                         {
                                            result=false;
                                          }
                                          val=$.trim(val);
                                         $("#<portlet:namespace />employeeName").val(val);
                                      return result;
                                        }
                            </aui:validator>
                           <aui:validator name="minLength">2</aui:validator>
                           <aui:validator name="maxLength">80</aui:validator>
                     </aui:input>
              </aui:column>
              <aui:column columnWidth="15">
                     <label>Mobile :<span style="color: red;"> *</span></label>
              </aui:column>
              <aui:column columnWidth="35">
                     <aui:input type="text" name="mobile" label="" inlineLabel="true"
                           maxlength="10">
                           <aui:validator name="required"></aui:validator>
                           <aui:validator name="digits" />
                           <aui:validator name="minLength"
                                  errorMessage="Please enter atleast 10 digits">10</aui:validator>
                           <aui:validator name="maxLength"
                                  errorMessage="Please enter no more than 10 digits">10</aui:validator>
                           <aui:validator name="custom"
                                  errorMessage="Please enter the valid mobile number">
                            function (val, fieldNode, ruleValue)
                             {
                                var result = true;
                                var pattern=/^[1-9][0-9]+/;
                                var check = pattern.test(val);
                                if(check == false)
                                {
                                  result=false;
                                }
                                val=$.trim(val);
                                $("#<portlet:namespace />mobile").val(val);
                                return result;
                              }
                            </aui:validator>
                     </aui:input>
              </aui:column>
       </aui:field-wrapper>
       <br />
       <aui:field-wrapper>
              <aui:column columnWidth="15">
                     <label>Email :<span style="color: red;"> *</span></label>
              </aui:column>
              <aui:column columnWidth="35">
                     <aui:input type="text" name="email" label="" inlineLabel="true">
                           <aui:validator name="required"></aui:validator>
                           <aui:validator name="email"></aui:validator>
                           <aui:validator name="custom">
                            function (val, fieldNode, ruleValue)
                              {
                                 var result = true;
                                 val=$.trim(val);
                                 $("#<portlet:namespace />email").val(val);
                                 return result;
                               }
                            </aui:validator>
                     </aui:input>
              </aui:column>
              <aui:column columnWidth="15">
                     <label>Company Name :<span style="color: red;"> *</span></label>
              </aui:column>
              <aui:column columnWidth="35">
                     <aui:input type="text" name="companyName" label="" inlineLabel="true">
                           <aui:validator name="custom"
                                  errorMessage="Please enter the valid company name">
                            function (val, fieldNode, ruleValue)
                             {
                              var result = true;
                              var pattern=/(?=.*[a-zA-Z])[a-zA-Z0-9 &@!#_\-\\\/\.]+/;
                              var check = pattern.test(val);
                          var checkValue = $("#<portlet:namespace />companyName").val();
                            if(check == false && checkValue)
                            {
                               result=false;
                            }
                            val=$.trim(val);
                          $("#<portlet:namespace />companyName").val(val);
                          return result;
                           }
                         </aui:validator>
                     </aui:input>
              </aui:column>
       </aui:field-wrapper>
       <br />
       <aui:field-wrapper>
              <aui:column columnWidth="15">
                     <label>Password :<span style="color: red;"> *</span></label>
              </aui:column>
              <aui:column columnWidth="35">
                     <aui:input name="password1" type="password" id="password1" label=""
                           showRequiredLabel="<%=false%>">
                           <aui:validator name="required" />
                           <aui:validator name="equalTo">'#<portlet:namespace />password2'</aui:validator>
                     </aui:input>
              </aui:column>
              <aui:column columnWidth="15">
                     <label>Confirm Password :<span style="color: red;"> *</span></label>
              </aui:column>
              <aui:column columnWidth="35">
                     <aui:input name="password2" type="password" id="password2" label=""
                           showRequiredLabel="<%=false%>">
                           <aui:validator name="required" />
                           <aui:validator name="equalTo">'#<portlet:namespace />password1'</aui:validator>
                     </aui:input>
              </aui:column>
       </aui:field-wrapper>
       <br />
       <aui:field-wrapper>
              <aui:column columnWidth="15">
                     <label>Pan Card Number :<span style="color: red;"> *</span></label>
              </aui:column>
              <aui:column columnWidth="35">
                     <aui:input name="panCardNumber" type="text" label=""
                           inlineLabel="true">
                      <aui:validator name="custom"
                                  errorMessage="Please enter the valid pan card number">
                       function (val, fieldNode, ruleValue)
                       {
                         var result = true;
                         var pattern=/^[A-Z]{5}\d{4}[A-Z]{1}$/;
                         var check = pattern.test(val);
                         var checkValue = $("#<portlet:namespace />panCardNumber").val();
                         if(check == false && checkValue)
                          {
                           result=false;
                          }
                         val=$.trim(val);
                         $("#<portlet:namespace />panCardNumber").val(val);
                         return result;
                        }
                       </aui:validator>
                     </aui:input>
              </aui:column>
              <aui:column columnWidth="15">
                     <label>Compensation :<b style="color: red;"> *</b></label>
              </aui:column>
              <aui:column columnWidth="35">
                     <aui:input name="compensation" type="text" id="compensation" label=""
                           inlineLabel="true">
                        <aui:validator name="custom"
                                  errorMessage="Please enter the valid Compensation">
                        function (val, fieldNode, ruleValue)
                        {
                         var result = true;
                         var pattern =/(^\d{0,4}\.\d{0,2})|(^\d{0,4})$/gm;
                         var check = pattern.test(val);
                         var checkValue = $("#<portlet:namespace />compensation").val();
                         if(check == false && checkValue)
                           {
                              result=false;
                           }
                          val=$.trim(val);
                         $("#<portlet:namespace />compensation").val(val);
                         return result;
                         }
                        </aui:validator>
                     </aui:input>
              </aui:column>
       </aui:field-wrapper>
       <br />
       <aui:field-wrapper>
              <aui:column columnWidth="15">
                     <label>Experience :<b style="color: red;"> *</b></label>
              </aui:column>
              <aui:column columnWidth="35">
                     <aui:input name="experience" id="experience" type="text" label=""
                           inlineLabel="true">
                           <aui:validator name="required" />
                           <aui:validator name="custom"
                                  errorMessage="Please enter the valid Experience">
                          function (val, fieldNode, ruleValue)
                          {
                           var result = true;
                           var pattern =/(((^([0-9]|[1-3][0-9]|4[0-9]))+(?:\.([0-9]|(?:[0-0][0-9]|[1-1][0-1]))){1,2})|(^([0-9]|[1-3][0-9]|4[0-9])))$/;
                          var check = pattern.test(val);
                          var checkValue = $("#<portlet:namespace />experience").val();
                          if(check == false && checkValue)
                          {
                              result=false;
                          }
                         val=$.trim(val);
                        $("#<portlet:namespace />experience").val(val);
                        return result;
                         }
                        </aui:validator>
                     </aui:input>
              </aui:column>
              <aui:column columnWidth="15">
                     <label>Postal Code :<b style="color: red;"> *</b></label>
              </aui:column>
              <aui:column columnWidth="35">
                   <aui:input name="postalCode" id="postalCode" type="text" label="">
                     <aui:validator name="required" />
                    <aui:validator name="custom"
                                  errorMessage="Enter the valid Postal Code">
                    function (val, fieldNode, ruleValue)
                     {
                      var result = true;
                      var pattern=/^([1-9])([0-9]){5}$/;
                      var check = pattern.test(val);
                      if(check == false)
                         {
                           result=false;
                         }
                       val=$.trim(val);
                     $("#<portlet:namespace />postalCode").val(val);
                     return result;
                     }
                   </aui:validator>
                 </aui:input>
              </aui:column>
       </aui:field-wrapper>
       <br />
       <aui:column columnWidth="15">
       </aui:column>
       <aui:column columnWidth="25">
       </aui:column>
       <aui:column columnWidth="60">
              <aui:button type="submit" value="Submit" name="saveEmployeeForm"></aui:button>
       </aui:column>
</aui:form>
<!-- Useful patterns -->
<!--
                    
               1)For Website
                     var pattern=/^((http|https):[\/][\/]|www.)([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
               2)Pattern for numbers upto 200
                  var pattern=/^(([0-9])|([0-9][0-9])|([0-1][0-9][0-9]))$/;
               3)digits comma digits
                     var pattern=/^\d+(,\d+)*$/;
               4)IFSC code validation
                 var pattern=/[A-Z|a-z]{4}[0][\d]{6}$/;
               5)Address validation
                 var pattern=/(?=.*[a-zA-Z])[a-zA-Z0-9 @!#,_\-\\\/\.]+/;
               6)Capability validation
                 var pattern=/(?=.*[a-zA-Z])[a-zA-Z0-9 +&,#_\-\/\.]+/;
               
               -->