Skip to main content

The Ultimate Guide to Liferay DXP Performance Tuning: Speed Up Your Portal

The Ultimate Guide to Liferay DXP Performance Tuning: Speed Up Your Portal In the enterprise web space, milliseconds equal millions. Whether you are running a B2B commerce storefront, a customer support portal, or an employee intranet on Liferay DXP, slow load times will devastate your user experience and destroy your SEO rankings. Out of the box, Liferay is configured to run on almost any machine. This means its default settings are highly conservative to ensure compatibility, not maximum performance. If you are launching a production environment without tuning your server, you are leaving massive amounts of speed and scalability on the table. In this comprehensive, deep-dive guide, we are going to explore the critical layers of Liferay performance tuning. We will cover backend Java Virtual Machine (JVM) configuration, Database Connection Pooling, Elasticsearch optimization, and Frontend caching strategies. By the end of this guide, you will have a blazing-fast, enterprise-grade...

How to create new site programmaticly in liferay with validation

Create site in liferay

<%@page import="javax.portlet.PortletPreferences"%>
<%@page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@page import="com.liferay.portal.kernel.util.HtmlUtil"%>
<%@page import="com.liferay.portal.kernel.util.StringPool"%>
<%@page import="com.liferay.portal.kernel.util.UnicodeProperties"%>
<%@page import="com.liferay.portal.service.LayoutSetPrototypeServiceUtil"%>
<%@page import="com.liferay.portal.model.LayoutSetPrototype"%>
<%@page import="com.liferay.portal.service.GroupLocalServiceUtil"%>
<%@page import="java.util.List"%>
<%@page import="com.liferay.portal.kernel.bean.BeanParamUtil"%>
<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@page import="com.liferay.portal.model.Group"%>
<%@page import="com.liferay.portal.kernel.util.WebKeys"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/theme"  prefix="theme"%>
<%@taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
 <%@taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<%@taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>

<portlet:defineObjects />
<theme:defineObjects/>

<%

PortletPreferences commonpref = renderRequest.getPreferences();
String commonvalue = (String)commonpref.getValue("commonvalue", "Hello! Welcome to our portal.");
//Group group = (Group)request.getAttribute("site.group");
//Group liveGroup = (Group)request.getAttribute("site.liveGroup");
LayoutSetPrototype layoutSetPrototype = (LayoutSetPrototype)request.getAttribute("site.layoutSetPrototype");
//boolean showPrototypes = GetterUtil.getBoolean(request.getAttribute("site.showPrototypes"));

long companyid=company.getCompanyId();
String languageid=user.getLanguageId();



long liveGroupId = 0;
//Group group = (Group)request.getAttribute(WebKeys.);
List<Group> objgroup=GroupLocalServiceUtil.getGroups(0, GroupLocalServiceUtil.getGroupsCount());
Group group=objgroup.get(0);
long groupId = BeanParamUtil.getLong(group, request, "groupId");

System.out.println("Here are group :"+group);
Group stagingGroup = null;

Group liveGroup = null;

if (group != null) {
    if (group.isStagingGroup()) {
        liveGroup = group.getLiveGroup();

        stagingGroup = group;
    }
    else {
        liveGroup = group;

        if (group.hasStagingGroup()) {
            stagingGroup = group.getStagingGroup();
        }
    }
}
    liveGroupId = liveGroup.getGroupId();
    System.out.println("Here are livegroup id :"+liveGroupId);
    request.setAttribute("group", group);
%>
<%=commonvalue %>
<portlet:actionURL var="creatURL" name="Create">
<portlet:param name="viewJSP" value="/html/business/view.jsp"></portlet:param>

</portlet:actionURL>

<aui:form action="<%=creatURL %>" method="post">

<liferay-ui:error key="sitename" message="The site you has enter already eits" />
<aui:input name="commonvalue" type="hidden" value="<%=commonvalue %>"/>
<aui:input name="liveGroupId" type="hidden" value="<%=liveGroupId%>" />
<aui:input name="companyid" type="hidden" value="<%=companyid%>" />
<aui:input name="languageid" type="hidden" value="<%=languageid%>" />
<aui:input name="groupId" type="hidden" value="<%= groupId %>" />
<aui:input name="group" type="hidden" value="<%= group %>" />
<aui:input name="sitename" label="Enter Site" type="text" value="">
<aui:validator name="required"></aui:validator></aui:input>
<aui:input name="discription" label="Enter site discription" type="textarea" value="">
</aui:input>



 <aui:button type="submit" value="Create site" ></aui:button>
 


                           

                               
</aui:form>



Here are action file


package com.business.awaz;

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

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletModeException;
import javax.portlet.ReadOnlyException;
import javax.portlet.ValidatorException;
import javax.portlet.WindowStateException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.util.HtmlUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.UnicodeProperties;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.LayoutConstants;
import com.liferay.portal.model.LayoutSet;
import com.liferay.portal.model.LayoutSetPrototype;

 import com.liferay.portal.service.GroupServiceUtil;

import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.LayoutServiceUtil;
import com.liferay.portal.service.LayoutSetLocalServiceUtil;
import com.liferay.portal.service.LayoutSetPrototypeServiceUtil;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.ServiceContextFactory;
import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;

import javax.portlet.PortletPreferences;
//import com.liferay.portlet.sites.util.SitesUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;



/**
 * Portlet implementation class Business
 */
public class Business extends MVCPortlet {
    public void fiveplan(ActionRequest fiveplanrequest,ActionResponse fiveplanresponse) throws ReadOnlyException, ValidatorException, IOException, PortletModeException, WindowStateException
    {
        String fiveplane=fiveplanrequest.getParameter("basicplan");   
       
        PortletPreferences fiveplanpref=fiveplanrequest.getPreferences();
                
        if(fiveplane !=null)
        {
            fiveplanpref.setValue("commonvalue", fiveplane);
            fiveplanpref.store();   
           
            fiveplanresponse.setRenderParameter("jspPage","/html/business/createsite.jsp");
           
        }


    }
   
       
   
    public void Create(ActionRequest actionRequest ,ActionResponse res) throws Exception
    {
           
        try {
            String sitename=actionRequest.getParameter("sitename");
             String findsitename="";
              List<Group> siteobj=GroupLocalServiceUtil.getGroups(0, GroupLocalServiceUtil.getGroupsCount());
                for(int k=0;k<siteobj.size();k++)
                {
               
                    if(sitename.equals(siteobj.get(k).getName()))
                    {
                        //SessionErrors.add(actionRequest, "sitename");
                        findsitename=siteobj.get(k).getName();
                    }
           
                }
             String commonvalue=actionRequest.getParameter("commonvalue");

                long liveGroupId = Long.parseLong(actionRequest.getParameter("liveGroupId"));
                long companyid=Long.parseLong(actionRequest.getParameter("companyid"));
                String languageid=actionRequest.getParameter("languageid");
                String discription=actionRequest.getParameter("discription");
                System.out.println("Here is domain name"+sitename);
                System.out.println("Here is group name"+liveGroupId);
                int type = ParamUtil.getInteger(actionRequest, "type");
                String friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
                System.out.println("Friendlay URL is :"+friendlyURL);
                ServiceContext serviceContext = ServiceContextFactory.getInstance(Group.class.getName(), actionRequest);
                Group liveGroup = null;
                String oldFriendlyURL = null;
                String oldStagingFriendlyURL = null;
                long privateLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId");
                long publicLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId");
                System.out.println("Here are private id: :"+privateLayoutSetPrototypeId);
                System.out.println("Here are public id: :"+publicLayoutSetPrototypeId);
                System.out.println("Here are servicecontext id: :"+serviceContext);
                ServiceContext serviceContexta = new ServiceContext();
                Group liveGroups = null;
                       
               List<LayoutSetPrototype> layoutSetPrototypes = LayoutSetPrototypeServiceUtil.search(companyid, Boolean.TRUE, null);
                            String uuid=null;
                            for (LayoutSetPrototype curLayoutSetPrototype : layoutSetPrototypes)
                                {
                                UnicodeProperties settingsProperties = curLayoutSetPrototype.getSettingsProperties();
                                String servletContextName = settingsProperties.getProperty("customJspServletContextName", StringPool.BLANK);
                                String name=HtmlUtil.escape(curLayoutSetPrototype.getName(languageid));
                                System.out.println("hi this is :"+ curLayoutSetPrototype.getLayoutSetPrototypeId());
                   
                                  if(commonvalue.equals(name))
                                      {
                                    uuid=  curLayoutSetPrototype.getUuid();
                                      }
                                      name="";
                                }
                                 
                                  if(!uuid.equals(""))
                                  {
                                        
                                     if(findsitename.equals(""))       
                                     
                                     {                                   
                                    GroupServiceUtil.addGroup(sitename,discription, 1, friendlyURL, true, true ,serviceContext);

                                    Group groupobj=GroupLocalServiceUtil.fetchGroup(companyid, sitename);
                                    long groupid=groupobj.getGroupId();
                                   System.out.println("Site is creates");
                                   LayoutSet layoutsets=LayoutSetLocalServiceUtil.getLayoutSet(groupid,false);
                           
                                   layoutsets.setLayoutSetId(layoutsets.getLayoutSetId());
                                   layoutsets.setGroupId(layoutsets.getGroupId());
                                   layoutsets.setCompanyId(layoutsets.getCompanyId());
                                   layoutsets.setCreateDate(layoutsets.getCreateDate());
                                   layoutsets.setModifiedDate(layoutsets.getModifiedDate());
                                   layoutsets.setPrivateLayout(layoutsets.getPrivateLayout());
                                   layoutsets.setLogo(layoutsets.getLogo());
                                   layoutsets.setLogoId(layoutsets.getLogoId());
                                   layoutsets.setThemeId(layoutsets.getThemeId());
                                   layoutsets.setColorSchemeId(layoutsets.getColorSchemeId());
                                   layoutsets.setWapThemeId(layoutsets.getWapThemeId());
                                   layoutsets.setWapColorSchemeId(layoutsets.getWapColorSchemeId());
                                   layoutsets.setCss(layoutsets.getCss());
                                   layoutsets.setPageCount(1);
                                   layoutsets.setSettings(layoutsets.getSettings());
                                   layoutsets.setLayoutSetPrototypeUuid(uuid);
                                   layoutsets.setLayoutSetPrototypeLinkEnabled(true);
                               
                                   LayoutSetLocalServiceUtil.updateLayoutSet(layoutsets);
       


                           
                                   boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
                                   long parentLayoutId = ParamUtil.getLong(actionRequest, "parentLayoutId");
                                   String name1 = ParamUtil.getString(actionRequest, "name", "home");
                                   String title = StringPool.BLANK;
                                  String description = StringPool.BLANK;
                         
                                   boolean hidden = false;
                                   String friendlyURL1 = StringPool.BLANK;
                           

                                   ServiceContext serviceContext1 = ServiceContextFactory.getInstance(actionRequest);
                                   System.out.println("Service cintext is "+serviceContext1);
                           
                                   System.out.println("Here are new site id"+groupid);
                   
                                  LayoutServiceUtil.addLayout(groupid, false ,parentLayoutId ,name1 ,title ,description ,LayoutConstants.TYPE_PORTLET ,false ,friendlyURL1,serviceContext);
                                  res.setRenderParameter("jspPage", "/html/business/createsite.jsp");
                           
                                         }
                                    else
                                    {
                                   
                                    SessionErrors.add(actionRequest, "sitename");
                                  
                                   
                                    }
                                             
                                        
                                  }
       
             }
        catch (SystemException e) {
            // TODO Auto-generated catch block
                            e.printStackTrace();
        }   
       
    }
   
}

Comments

Post a Comment

Popular posts from this blog

service builder with crud operation in liferay

   Crud and Search opration in Liferay:      ->  Liferay use service builder techniq for Crud opration.    ->  Service builder purform by  Service.xml file.    ->  Service.xml file create table in database and also create class and diffrent method.   1)      Create service.xml file.             ->Create service.xml file in WEB-INF and write below code.             ->CODE:        < service-builder package-path = "com.test" >         < namespace > qr </ namespace >           < entity name = "Searchclass" local-service = "true"                     ...

Liferay Objects in 7.4: Build Full Applications Without Coding

Liferay Objects in 7.4: Build Full Applications Without Coding Meta Description: Learn how to use Liferay Objects in 7.4 to build full-stack applications without Service Builder. Step-by-step guide with real examples. Keywords: Liferay Objects, Liferay 7.4, Liferay tutorial, Liferay API, Liferay development, low code platform 🚀 Introduction If you have worked with Liferay earlier, you probably remember the pain of Service Builder—writing XML, generating code, deploying modules, and managing OSGi. In my experience working on Liferay-based portals , even a simple CRUD feature used to take hours or sometimes days. But with Liferay 7.4, everything changed. Liferay Objects is a powerful low-code feature that allows you to create database entities, APIs, and UI directly from the browser—without writing backend code. --- 📌 What are Liferay Objects? Liferay Objects allow you to build applications directly from the Control Panel UI. Create database tables Define re...