Sunday, September 11, 2016

Liferay Interview Questions

  • Liferay Basics

  • What is a portal?
  • What is a portlet container and explain more about it.
  • What is a portlet?
  • What are the prerequisites to set up the Liferay in your local machine?
  • What is the current running version of Liferay?
  • What are all Liferay versions?
  • What is meant by GA in Liferay versions?
  • What is meant by stable version and Beta version?
  • What are the features of a portal?
  • What is JSR?
  • What is the difference between JSR 168 and JSR 286?
  • Who framed these JSR 168 and JSR 286 standards?
  • What is the difference between Portlet and Servlet?
  • What is the use of a theme in Liferay?
  • What is the use of layout in a portal?
  • What are the advantages of the Liferay portal?
  • What is the Differences between personalization and customization?
  • What is the Difference between Authentication and Authorization?
  • What is meant by collaboration?
  • What is the use of file and how we can use in the Liferay portal?
  • What is a Liferay portal instance?
  • Can we configured multiple domains on a single Liferay instance and hook

  • Portlet

  • What is portlet?
  • What is the Life Cycle of a portlet?
  • How many portlet life cycle methods given by JSR 168 and what are they?
  • How many portlet life cycle methods given by JSR 268 and what are they?
  • What are the portlet modes and what is the use of the modes.
  • What are the important descriptor files   to run and manage the custom portlets in the Liferay portal?
  • What are the key configurations we can place in portlet.xml file?
  • What are the key configurations we can place in liferay-portlet.xml file?
  • What are the key configurations we can place in liferay-display.xml file?
  • What are the configurations we can place in the file?
  • Where we can create a portlet category and segregate the portlet under that category.
  • How can we register a portlet with the portlet container?
  • How we can register the configuration page implementation class in a portlet.
  • Where we can configure file of a portlet and how to use the file properties in the portlet.
  • What is meant by <instanceable>true</instanceable>?
  • What is meant by <instanceable>false</instanceable>.
  • How to configure multiple portlets in a single folder structure.
  • How to Support Internationalization (i18n) On Liferay Portlets.
  • How to use jQuery in the Liferay portlet
  • What are the global files in a custom portlet w.r.t CSS and JS and where we configure in order to make availability of those files to the JSP files automatically (without including those in the JSP files)
  • Draw the portlet autonomy
  • What is the difference between render URL, action URL and resource URL in the Liferay portlet?
  • What are the window states of a Liferay Portlet?
  • What is portlet preferences?
  • What is the structure of normal MVC portlet in Liferay?
  • What is the structure of Spring MVC portlet in Liferay?
  • Explain about the Liferay search container in the Liferay portlet
  • Explain the process to implement Ajax calls in Liferay
  • The process to create pop ups in Liferay portlet.
  • Explain the process to create tabs in the Liferay portlet
  • How can we read the portal properties in the portlet using Liferay API?
  • How to embed a Liferay portlet in other non Liferay websites

  • Liferay Hooks

  • What is the use of an EXT in Liferay Portal?
  • What is the use of a Hook in Liferay Portal?
  • What is the difference between EXT and hooks
  • How to override a portal services using hook.
  • What are the disadvantages with the EXT.?
  • What are the disadvantages with the Hook?
  • How to override Liferay struts actions by the hook

  • Liferay Service Builder

  • What is a service builder?
  • What is the use of namespace in service.xml file?
  • What is the purpose of specifying local-service=true in service.xml file
  • What is the purpose of specifying remote-service=true in service.xml file
  • What are the service layers created by the service builder and explain them briefly.
  • What is the process to define finder methods in the service builder?
  • What is the process to define custom SQL methods in the service builder?
  • When will be the database table will create in the given database w.r.t the service builder.
  • Is there a build number associated to a portlet assigned by the service builder? Where can we find the current build number?
  • What is the purpose of mode and persistence packages which are created by the Liferay service builder?
  • Can we set multiple databases with Liferay Portal?
  • Where you can write custom methods in auto generated service layer by service builder
  • Explain the process to implement web services methods w.r.t generated service layer in Liferay.
  • Explain generate native mobile Liferay service libraries in Liferay?
  • Explain Liferay cache mechanism.
  • How to disable Liferay cache to Liferay portal entities and custom entities.
  • How disable Liferay cache to Finder methods.
  • How to implement transaction roll back in Liferay services.
  • What is Liferay Dynamic Query?
  • What is different between findBy and fetchBy methods in Liferay services?
  • Does Liferay Support Foreign Key relation?
  • How to implement One to Many and Many to Many relationship in Liferay.
  • What is Liferay Model Listeners and its importance?
  • What is different between XXXLocalServices and XXXServices?
  • What is PrincipalException in Liferay and when it occurred?
  • How to expose one plugin services with other plugin?
  • Can we implement multiple Data sources in Liferay and explain the mechanism to implement it.
  • How to expose Liferay service as web services
  • Explain how to generate web services in Liferay
  • What Liferay Mobile SDK?

  • Liferay Themes

  • What is theme and explain the process to create a customized theme
  • How to embed a portlet in a theme
  • What is the use of theme settings in a theme .Explain with one use case?
  • What is the CSS file we use to customize the portlet title, border colors?
  • Draw anatomy of a theme
  • How to place multiple themes in a single folder structure and what is the use of doing this with one use case
  • What are the implicit variables in a theme velocity file?
  • How to get the Liferay portal service classes in a theme velocity file
  • What is the process to apply a theme to a page as well as a website?
  • Explain Liferay Theme Setting.
  • Explain what Liferay Theme color screams.
  • What are the languages we can use to implement Liferay theme templates?

  • Liferay Layouts

  • How to create a layout in Liferay.
  • Draw the anatomy of a layout.
  • What is the process to apply a layout to a page?
  • How to embed portlet in Layout?

  • Liferay Administration

  • What is role in Liferay?
  • How many types of roles are exists in Liferay portal. What are they?
  • What is Inherited Roles in Liferay?
  • What is meant by user group?
  • What is meant by Team?
  • What is the difference between an organization and site?
  • What is Location organization?
  • Can we have multiple organizations with same name in Liferay portal?
  • What is a site template?
  • What is a page template?
  • What is the process to assign a role to the user from control panel?
  • What is the process to define permissions on a role?
  • Explain about server administration
  • How to install Liferay market place apps from the control panel
  • How to uninstall a portlet from the server through control panel
  • How to configure email server credentials in the control panel
  • Explain the process of LDAP authentication in Liferay
  • What is the process to see the portal properties in the control panel?
  • What is DL (Document Library) in Liferay?
  • How does Liferay document library implemented in Liferay and what is repository implementation Liferay using?
  • Can we store documents and files in database in Liferay?
  • How to change file system and its repositories in Liferay

  • Others

  • What is an IPC and how you can implement IPC in Liferay
  • What are the differences between IPC using event and IPC using public render
  • Explain about the structures, templates and article with real time scenario.
  • Explain the Kaleo work flow management.
  • How to implement workflow for custom entity?
  • Explain SOLR Integration with Liferay.
  • Explain how to implement SSO (Single Sign On) in Liferay.
  • How many ways we can Implement SSO in Liferay.


Tuesday, July 26, 2016

Liferay Permission checker for guest user

Liferay has permission checker where user related permissions are available. Whenever we are giving access to specific resources then we will use permission checker. From permission checker we will use has permission to check the user permissions, permission checker object will be ready when the user login into the Liferay portal.

In JSP level we will use following code to get user permission checker Object.

PermissionChecker permissionCheckerObj = themeDisplay.getPermissionChecker();

Or We have JSP implicit variable for permission checker as follows.


Finally we will use has permission method to check whether user have permission or not as follows.


Another scenario where we are calling XXXServiceUtil methods of service layer, these are services which need to passing through permission checker and permission checker will check whether user has right permission to call these methods or not, otherwise it throws PrincipalException says that permission checker is not set.

Generally XXXServiceUtil methods are for login user or user should have right permission to use these calls otherwise it throws exception.





Above methods calls will fails when we are invoking as guest user, it means executing these methods without login into Liferay portal. If the user does not have right permission to call these methods then it will throw following exception stack trace.
            at com.liferay.portal.service.permission.
            at com.liferay.portal.service.permission.
            at com.liferay.portlet.expando.service.

But we can call these methods as guest user and we will call these methods on behalf of Admin user permission checker object such way we can use these services.

The following is code to call XXXServiceUtil methods on behalf of administrator and this will work any time it means whether you login into portal or not.

The following is example

Role adminRole = RoleLocalServiceUtil.getRole(CompanyThreadLocal.getCompanyId(), "Administrator");
List<User> adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());
long userId = 20159;
if(adminUsers != null && !adminUsers.isEmpty()) {
            userId = adminUsers.get(0).getUserId();
User user1 = UserLocalServiceUtil.getUser(userId);
PermissionChecker checker = PermissionCheckerFactoryUtil.create(user);

 We need to get admin user and we can create permission checker object, finally we will set permission object to Permission Thread Local so that permission checker is available. Once you set permission checker next code lines we can call XXXServiceUtil methods then it will be successfully invoked.


This is not recommended way but some scenarios when it needed where we can use it.
Let’s say we are writing some application start up hooks where we may need use  XXXServiceUtil methods need to be called then it will be useful. Because we are not sure while deploy the hook portal is login with user or not, otherwise method invocation will get failed after deployment of hook.

Let’s say in our custom portlet service layer we may need portal XXXServiceUtil methods in that scenarios also we can use it.

All of methods are available in XXXLocalServiceUtil but some scenarios if not available then it may useful.

Sunday, July 24, 2016

Liferay Upgrade Process

Liferay Upgrade process is way to perform pre configurations related to portlet or Liferay applications.

When we can use Upgrade Process?
  1. When we move our applications from one version to another version we may need to do some pre configuration to work well in newer environment.
  2. If application need to populate some default data with respect application.
  3. Database related SQL script execution.

Upgrade Process will be implemented through hooks in Liferay. We can create a separate hook plugin or we can create with in the portlet as hook.

  1. Implement Upgrade Process Java Class.
  2. Configure Upgrade Process details in hook properties file.

Implement Upgrade Process Java Class

We need to implement one Upgrade process java class and that must be extends UpgradeProcess class. We will write all configuration logic in doUpgrade(--)

public class CustomUpgradeProcessProcess_1_1_0 extends UpgradeProcess {
public int getThreshold() {
return 110;
protected void doUpgrade() throws Exception {"=====Upgrade Process Started=====");


protected void setUpApplication() throws Exception {"=====Upgrade Process Logic here=====");
protected void runStatesSQL() throws Exception {"=====Upgrade Process Executing SQL Script=====");
runSQL("INSERT INTO Region VALUES (1085,108,'IN_AP','Andhra Pradesh',1) ,(1086,108,'IN_TN','TamilNadu',1),(1087,108,'IN_AR','Arunachal Pradesh',1)");

private static Log _log = LogFactoryUtil.getLog(CustomUpgradeProcessProcess_1_1_0.class);

Threshold is a number it will be stored in release_ table. When we deploy hook then it will check with the number that already stored in release_. If the number is higher than the value in release_ table then it will trigger the upgrade process.

runSQL(--) is a method to execute SQL script. We need to provide a valid SQL script.
doUpgrade(--) is a method will trigger when hook is deployed successfully.

Configure Upgrade Process Details in hook properties file

Now we need to configure Upgrade process information in hook properties file.


If we have multiple process then separate with new line

    com. meera.upgrade.SetupOrganizationApplicationProcess_1_1_0,\
    com. meera.upgrade.SetupSiteApplicationProcess_1_1_0

Build number is stored in release_ after upgrade process completed successfully. Generally this will be current build number which is available in portlet file.

Once upgrade processes is completed then build number will be stored in Liferay relase_ table. When we deploy same hook for next time, it won’t start upgrade process again.
If you want to run upgrade process again then we will create another java class with higher number and need to change build number in hook properties file.

The following screen shows that build number stored in release_ table against upgrade processes hook.

Sample Application:

Assume we have a requirement where we wanted to create organization with some default pages.

We will use upgrade process hook, with that we will create Organization. Once organization is created, we will create some default pages for it.

Complete Code example

Upgrade Process Java Class (SetupOrganizationApplicationProcess_1_1_0)

package com.meera.upgrade.process;

import java.util.ArrayList;
import java.util.List;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.upgrade.UpgradeProcess;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.CountryConstants;
import com.liferay.portal.model.Layout;
import com.liferay.portal.model.LayoutConstants;
import com.liferay.portal.model.ListTypeConstants;
import com.liferay.portal.model.Organization;
import com.liferay.portal.model.OrganizationConstants;
import com.liferay.portal.model.RegionConstants;
import com.liferay.portal.model.Role;
import com.liferay.portal.model.User;
import com.liferay.portal.service.LayoutLocalServiceUtil;
import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.RoleLocalServiceUtil;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;

* @author meeraprince
public class SetupOrganizationApplicationProcess_1_1_0 extends UpgradeProcess {
public static String[] pageNames ={"Welcome","Products","Services","Contact Us"};
public static String ORG_NAME = "LiferaySavvy";
public int getThreshold() {
return 110;
protected void doUpgrade() throws Exception {"==========SetupApplicationProcess_1_1_0===============");

protected void setUpApplication() throws Exception {
Organization organization = createOrganization();
}catch(Exception e){

protected Organization createOrganization() throws Exception {"createOrganization Process started");
Organization organization = null;
boolean site = true;
String name = ORG_NAME;
String type =  OrganizationConstants.TYPE_REGULAR_ORGANIZATION;
long regionId = RegionConstants.DEFAULT_REGION_ID;
long countryId = CountryConstants.DEFAULT_COUNTRY_ID;
long companyId = getCompanyId();
long userId = getAdminUserId();
ServiceContext serviceContext = new ServiceContext();
String friendlyURL = name;
friendlyURL = friendlyURL.replace(StringPool.SPACE,StringPool.DASH);
long parentOrganizationId = OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID;
organization = OrganizationLocalServiceUtil.getOrganization(companyId, name);
}catch(Exception e){
organization = OrganizationLocalServiceUtil.addOrganization(userId, parentOrganizationId, name, type, regionId, countryId, ListTypeConstants.ORGANIZATION_STATUS_DEFAULT,name, site, serviceContext);
}else{"Organization Name already existed in your Liferay Portal.");

}catch(Exception e){
return organization;
protected List<Layout> createPages(Organization organization) throws Exception {"createPages Started");
List<Layout> pagesList = new ArrayList<Layout>();
for (String pageName : pageNames) {
Layout page = createPage(organization,pageName);
return pagesList;
protected Layout createPage(Organization organization,String name) throws Exception {"createPage Started");
long userId = getAdminUserId();
long groupId = organization.getGroupId();
boolean privateLayout = false;
String title = name;
String description = name;
String type = LayoutConstants.TYPE_PORTLET;
boolean hidden = false;
String friendlyURL = name;
friendlyURL = friendlyURL.replace(StringPool.SPACE,StringPool.DASH);
friendlyURL = StringPool.FORWARD_SLASH + friendlyURL.toLowerCase();"friendlyURL"+friendlyURL);
ServiceContext serviceContext = new ServiceContext();
long parentLayoutId = 0L;
Layout layout = null;
layout = LayoutLocalServiceUtil.fetchLayoutByFriendlyURL(groupId, privateLayout, friendlyURL);
}catch (Exception e) {
try {

layout = LayoutLocalServiceUtil.addLayout(userId, groupId, privateLayout,parentLayoutId, name, title, description, type, hidden,
friendlyURL, serviceContext);
} catch (PortalException e){
return layout;
protected long getAdminUserId() throws Exception {
Role adminRole = RoleLocalServiceUtil.getRole(getCompanyId(), "Administrator");
List<User> adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());
long userId = 20159;
if(adminUsers != null && !adminUsers.isEmpty()) {
userId = adminUsers.get(0).getUserId();
return userId;
protected long getCompanyId() throws Exception {
return PortalUtil.getDefaultCompanyId();


protected void runStatesSQL() throws Exception {
runSQL("INSERT INTO Region VALUES (1085,108,'IN_AP','Andhra Pradesh',1) ,(1086,108,'IN_TN','TamilNadu',1)");
private static Log _log = LogFactoryUtil.getLog(SetupOrganizationApplicationProcess_1_1_0.class);

Hook properties configuration (

Download Upgrade Process Hook

After successful deployment of hook, organization will be created with default pages.
If we access the following URL then we can see newly created organization

Popular Posts

Recent Posts

Recent Posts Widget