25+ Liferay Interview Questions and Answers for Portal Developers

Liferay Interview Questions and Answers for Portal Developers
Liferay is one of the most popular JSR compliant open source portal. This can be used to drive multiple websites with variety of features and look and feel. Liferay is developed in Java and the major portlet development on it is also supported by Java and few other languages.

The latest releases of liferay has been really feature rich and seen a increasing demand in liferay developers in recent past. Managing multiple websites using single liferay server installation is one of the main reason of liferay gaining popularity.

Liferay jobs are really high paying jobs due to being specialized in portlet segment of java web application development. There are many other portals available with free and paid options. To be highly valuable developer you must focus your knowledge to the JSR way of portlet development, this will ensure you can do development on any other JSR comliant portal as well.

Another positive aspect of Liferay portlet development is "The Liferay marketplace", this can give you an opportunity to develop and sell your own portlet to big businesses and grow your own business.

I have worked on liferay for more than 5 years and found that following interview questions are must know before getting a decent liferay developer job.


What is a Liferay Portal?

In general, a web portal represents a web application that provides a single point of access to variety of information.

Functionality of a portal can extended very easily by creating custom applications that can run inside a portal. These applications are called portlets.

For running portlets you need application server that can run a portlet container spec (JSR168 or JSR286). There are dozens of free and enterprise portal products available.

Liferay portal is an open source portal and below are the benefits of using Liferay portal:

  • Content management system(Documents, Articles).
  • 2-stage,3-stage workflows and publishing.
  • Social networking. 4)Sites and organization basis pages.
  • Integration with third party like LDAP, Solr, SSO(CAS, Siteminder).
  • Portlets realted to Wiki's, News, Finance, Social, Workflow, Collaboration.
  • Compatible with different Operating systems, databases and APP servers.
  • Compatible with UI technologies and web services.
  • Compatible with different scripts like PHP, Ruby, Grails, Python.
  • Suppport of hot deployment feature.


What is a Portlet?

Liferay portal comes with different portlets by default. These portlets are nothing but different small applications running in the instance(portal). Portlets are pluggable software components that are managed in a web portal.

In general words you can call them as different catalogues as portlets produce fragments of markup code that are aggregated into a portal. So a portal page is displayed as a collection of portlet, thease multiple small applications together making a page of the site and these all pages together makes one community or enterprise portal. Hence a portlet (or collection of portlets) resembles a web-based application that is hosted in a portal.

Portlet is a small application to fulfill the requirement of certain domain. Inter portlet communication is supported under Liferay portal. Portlet support hot deployment feature of Liferay Portal.


What is the difference between Hook, EXT and Portlet?

Liferay provides 3 ways to extend the functionality of a Liferay portal. Each of the way fits is good for different needs.

Hook

Liferay portal comes with a bundle where all the default built in portlets exist. Typically if any customization required in terms of JSP (UI) and portal properties. We need to go by Hook implementation. Hook is supported by hot deployment. Liferay documentation suggests that - Whenever possible, hooks should be used in place of Ext plugins, as they are hot-deployable and more forward compatible.

Some common scenarios that require the use of a hook are
  • When you have to perform a custom action on portal startup
  • When you have to perform a custom action on user login
  • When you need to overwrite or extend portal JSPs
  • When you need to modify portal properties
  • When you need to replace a portal service with your own implementation.

EXT

Liferay EXT Plugins are the most powerful way to extend the portal functionality. If any customization required in the core level classes then it can be done through EXT for example LDAP users and user groups import modification. but here in EXT, restart would be required.

EXT Plugins should be used only in case the portal functionality can not be extended using Portlet of Hooks. The EXT plugins are complex to develop and may cause maintenance issues in case you are trying to upgrade.

From liferay documents, The main use cases in which an Ext plugin may be used are:

  • Customizations to portal.properties (that is not supported by Hook Plugins)
  • Customizing and making changes to the Struts Actions for portal
  • Customizations of the Liferay beans declared in Liferay's Spring files
  • Adding JSPs that are referenced from portal properties that can only be changed from an ext plugin (be sure to check if the property can be modified from a hook plugin before doing this)
  • Direct overwriting of a class (not recommended unless it's strictly necessary)



Portlet

Portlets are the most common and easiest way to extend and provide a custom functionality for a liferay portal. This is a small application to fulfill the requirement of certain domain. It is basically a bunch of code(Java Files, JSP, CSS, Java Scripts etc.). Portlet is supported by hot deployment.

Liferay also has a marketplace where a lot of useful portlets are available for download and these portlets can contributed by anyone in the world. We recently contributed a Speed reading portlet and a My IP Address portlet in this marketplace for free use by liferay community.


What JSR version Liferay implements? Why JSR compatibility is important while choosing a portal?

JSR is a "Java Specification Request". Liferay Portal is developed to adhere to JSR 168 and JSR 286 specifications.
This specification is created by committee of JEE portal vendors. This specification is designed to achieve interoperability between different portals and portlets.

Liferay supports mainly below JSRs.

JSR-168(Portlet 1.0)
JSR-286(Portlet 2.0)
JSR-127(JSF 1.0)
JSR-170
JSR-314(JSF 2.0)
JSR-329

Why these standards are defined?

These standards are defined for the benefit of portal users (end customers). Before these standards were born, portal customer were required to use one portal and there was no easy way to switch between different portal vendors. Earlier portal were very vendor specific and all functionality were developed using proprietary API, technology and programming techniques. The JSR 168 and JSR 286 standards have defined the way portlets can be developed that will help users in long run.


Benefits of Following JSR Standards

Following these standards will ensure that there is no vendor lock in. However this can be guaranteed only when the portlets are developed sticking to the standards.


What is a Portlet Lifecycle?

Following is the portlet lifecycle:

  • init():It mainly initializes the portlet.
  • render(): It takes the HTML output to User Interface. It mainly render the view in term of JSP/HTML code and show into the respective portlet.
  • Destroy: This method takes care of releasing the portlet resources.

What Is The Difference Between View Mode And Edit Mode Of Portlets?

The modes of a portlet are typically related to the types of operations a user can perform on the portlet. A view mode is where users are allowed to do read only operations, whereas in edit mode user can add/update the data in the portlet.

Each portlet mode has a method which handles it:
doView()
doEdit()
doHelp()

These methods will contain mainly our "traffic directing" logic, which are responsible to decide what view the user wants to see.

Once the view has been determined, we will forward on to methods which actually implement that view.
For standard portlet view modes have two views:

  • The default view which shows the list of items.
  • The form, where users will mainly do the add and edit action.

In this where end user can edit the particular item, is called edit mode of portlet.

What Is A Liferay Theme? What Are The Advantages Of Using Them?

Liferay themes are the way to customize look and feel of a liferay portal page. The themes are extendable components that can be deployed separately on a portal and each page on the portal can choose a different theme (if required).

Themes are really powerful way to run multiple websites from a single portal. You can host multiple websites on a single liferay portal with totally different look and feel. This allows you to be unique at the same time save a lot resources on website hosting.

A lot of companies use liferay for creating multiple unique websites with the help of extraordinary themes that can be easily developed.

Themes are also available from marketplace.

For developing on our own, we have option of using VM pages(Velocity templates). Liferay provides the feature to deploy the different themes into the portal same like portlets war files. So number of themes we can be deployed into Liferay portal and we can further select those themes for user interface as per the requirement of end user for different site or organization
pages.

How To Use LDAP Authentication With Liferay?

LDAP is lightweight directory access protocol that is most commonly used for authentication and authorization of users. LDAP mainly consists users and usergroups of any organization with certain serach filter like DN entries. In the control panel of liferay we have option to provide the LDAP settings so that portal can contact the third party like LDAP and fetch the required users and groups as per given mappings.

For example Active directory is a LDAP implementation which can store users. Liferay support integration of any LDAP implementation through its admin control panel.

We need to provide the settings in control panel - > portal settings -> LDAP
This will require LDAP URL, username, password, users search filters mappings, groups search filters mapping etc.

What Is Portal-ext.properties File? How This Can Be Configured And Used In Liferay?

Liferay Portal comes with default configurations that are stored in portal.property file. You can use portal-ext.properties file to override the values in portal.properties file.

This allows you a clean way to keep your own copy of configurations that can be used outside the portal at the same time you can easily upgrade the portal.

What Is Inter-portlet Communication? Why Is It Required To Use JSR Style Inter-portlet Communication?

Sometimes we have the requirement where we need to establish communication in between two portlets for example any action done in one portlet redirecting the end user to other portlet where some kind of result is displaying as per action done on first portlet.

So in this use case we have to use liferay inter-portlet communication mechanism which serve the action performed by end user in one portlet and provide the result to the second portlet where the action result needs to be displayed. We can say that it works on striker-catcher mechanism.

JSR style inter portlet communication ensures that your portlets are going to work on any other JSR compliant portal server. If you use a liferay specific way to communicate between portlets than you may not be able to deploy and run the same portlet war on another JSR compliant portal (e.g. Apache Pluto)

What Is A Liferay Portal Instance?

Liferay portal ships with the one liferay portal tomcat bundle which is up and running in any server with certain database settings. We can have more than one liferay instances running from one database.

Liferay Portal allows you to run more than one portal instance on a single server. The Portal Instances page of the control panel lets you manage these instances. Data for each portal instance are kept separate. All portal data, however, is kept in the same database.

Each portal instance requires its own domain name. Liferay will direct users to the proper portal instance based on this domain name. So before you configure an instance, we need to configure its domain name in our network first. When we are ready to add an instance, click the Instances tab - > Add button.
It will be prompted for four fields and a check box:

  • Web ID: A general convention is to use the domain name for this. It’s a user-generated ID for the instance.
  • Virtual Host: Put the domain name you configured in your network here. When users are directed to your Liferay server via this domain name, Liferay will then be able to send them to the proper portal instance.
  • Mail Domain: Enter the domain name for the mail host for this instance. Liferay will use this to send email notifications from the portal.
  • Max Users: Enter the maximum numbers of user accounts you would like your portal instance to support.
  • Active: Use this check box to choose whether to create an active or an inactive portal instance.

Now we need to click Save. Now navigate to the portal using new domain name. We will see that looks like a clean install of Liferay. This is our new portal instance which can now be up and running.

How Can I Configure Two Different Domain Names (e.g. First.example.com And Second.example.com) On Liferay?

At the time of creation of any site we need to provide domain names which further take it as site domain name. We need to provide the certain domain name as required through the control panel of liferay portal. Single instance of Liferay Portal supports hosting of two or more domain names via communities(sites).

When we will go to control panel -> Site settings -> we can provide the site URL, details like site(community) description, membership type, active status and virtual host.

How Can I Configure Liferay To Use Email Address As User Name Instead Of Screen Name?

We can set this from control panel -> portal settings -> Authentication -> LDAP -> How do users authenticate?. Here we can select whatever we require from email address,screen name or user ID. At the time of LDAP authentication, we need to provide the required LDAP mappings which basically reads all the details related to users and usergroups from LDAP directory and import into Liferay portal. At the time of this connection with third party we need to give the required field like authentication should be by email address or screen name or user ID.

How To Customize The Behavior Of Liferay Default Out Of The Box Portlets (e.g. Document View, Calendar, Blog, Wiki Etc) ?

If we need any customization, related to JSP and UI then we can implement this using Hooks. Liferay portal comes with a bundle where all the default built in portlets exist. If any customixation required in the core level classes then it can be done through EXT for example LDAP users and user groups import modification. but here in EXT, restart would be required.

What Is Liferay Service Builder? Is There Any Alternative To Use Service Builder? What Are The Advantages And Disadvantages Of Using It?


Liferay service builder is basically used to create the service layers for any business logic implementation. From developer point of view it is very helpfull as it used to create all the service layers automatic. Suppose we want to develop a portlet, for this we need to write all the required implementation classes, utility cleasses and other required classes. Service builder is used to create all these classes for developer, where they can add their business logic further and process the data and render the output to view as per the requirement.

As per the advantage, this service builder will create whole structure of the service layers for developer mainly. It really helps them to write the code and their logic in service builder created model implementations and service implementation classes. These classes comes with normal CRUD (create, update and delete)operations. For developer, no need to add anything extra as whole service and utility layers are already got created by service builder. It really speed up the developement process.

Service builder requires service.xml which is having some of the required entries. Each of the entry is basically called entity, which is having it's primary key fields with some other required fields. If we want to implement order and finder method, we can implement it by using this service.xml.

Each entity creates table into liferay configured database with the given column names and their types. We can create service.xml related local-service and remote-service by setting them value as "true". When we would run this build-service like below, this would create all the service layers(implementation, utility etc.) where developer can write their required business logic further. Creation of all the service-classes would be done by the build.xml, we need to build-services using this xml file into Ant view of IDE.

How To Set The Display Category Of A Custom Built Liferay Portlet ?

We can set the display category like below mentioned liferay-display.xml. Suppose we have developed one portlet where portlet ID we have provided. We need to enter the custom built liferay portlet into certain category like name "category.cms", "category.collaboration" etc. By doing this custom built liferay portlet would come in required category by clicking the add application feature of liferay as there would be many of portlets under different categories. So below tag we need to enter for the entry of a portlet into certain category.

<display>
<category name="category.cms">
<portlet id="20" />
</category>
</display>

How To Support Internationalization (i18n) On Liferay Portlets? How Do You Support Multiple Languages Without Writing Java Code In Liferay?

We can support internationalization (i18n) on Liferay portlets and through out this whole Liferay portal. We need to provide whatever language we need to support into LIferay portal. This is mainly reads the regions number and provide the available language like en_US(english), SG(singapore), zh_CN(simple chinease), zh_TW(traditional chinease), ja_JP(Japanease).

In the same way to provide support of multiple languages without writing java code in Liferay, we can use Locales this through out the portal,
portlet, hooks and themes. This entry we can provide into same portal-ext.properties which Liferay portal would read and provide all the translation accordingly.
locales=en_US,zh_CN,zh_TW,ja_JP,ko_KR

If we are writing some custom messages in out code then we need to provide the below property files also as per the called language and using of Locales would convert it accordingly. We can use LocaleUtil in our code which will convert the certain message given in language files.

For example we want the assetCategory title in multi languages then we need to use this assetCategory.getTitle(locale). So here whatever locale we have mentioned earlier would be in action and pick the given title name from certain locale related language.property file.

Language_en_US.properties
Language_zh_CN.properties
Language_zh_TW.properties



What Are The Advantages Of Using Tomcat Bundle Of Liferay Against Other App Servers (e.g. JBoss, Glassfish Or Others)?

It is possible to use Liferay with Liferay IDE with other then tomcat server bundles but there are some features or benefits that will not be available:
Native eclipse server adapter that supports launching and debugging.
Deployment via add/remove modules wizard would not be available.
Auto redeployment based on changes to project resources.


Which One Is Best To Start In A Clean Setup?

Liferay bundle with tomcat app server is the best one to start in a clean setup.


How Do You Perform Junit Tests On Your Portlet?

Junit tests are there to check the code mainly by providing the value of any method input parameter, how the method would work and gives the values.

public class MyEmployeeTest {
 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
   "ApplicationContext-service.xml");
 public void testMyMethod() {
  UserService employeeService = (UserService) context.getBean("userService");
  //Provide the user Id as 101581
  User user = storeService.findUserByUserId(1234);
  //get the employee
  Set employee = user.getEmployeesForUserId();
  System.out.println("Employee Name : "+employee.getName());
 }
}


How Will You Configure A Portlet That Can Be Added Multiple Times On A Portal Page?

One property is there in portlet.xml which is as follows:


<instanceable>true</instanceable>


by using the value true and false we can configure a portler that can be added multiple times on a portal page.


How Can You Customize Liferay Search Feature? What Are The APIs To Do It?

We can customize Liferay Search feature, depends upon our requirement by below two ways.

Hook : If changes are required as per the view side like we need to change the search result form view then we can write the Hook
to customize it.

EXT : If changes are required as per the core functionality like we need to change the search query term, we can implement EXT.


How Can You Integrate Liferay With An External Content Management System (e.g. Alfresco)

Liferay passes user credentials through CMIS to the alfresco in order to connect. To enable this in liferay, we need to enter following below property in portal-ext.properties which will allow liferay to store password in session.
session.store.password=true

Also one more thing we need to take into consideration is that Liferay passes logged in user's credentials to CMIS Repository (whihc is alfresco
here) as described above. What this means is that userid/password in liferay must match userid/password in Alfresco. Alfresco by default uses a loginid (which is similar to screen-name in liferay) to authenticate user. So we need to make liferay also authenticate using screen name by making following entry into portal-ext.properties.

company.security.auth.type=screenName

So we need to start Liferay. Login as administrator and go to control panel. we need to go to Document and Media which will bring up a screen where we need to click on Add -> New Repository. this will bring one screen where we basically provide connection details to connect to Alfresco like below.

Name: Give any name you want to give to your repository view in liferay. For example, I will give Alfresco repository name.
Description: A brief description about it.
Repository Type: We can connect either using AtomPub or using web services.
AtomPub URL: This will be the CMIS repository URL where our alfresco is running. In our case, it's would be http://localhost:8080/alfresco/service/api/cmis (Note: In case of Alfresco 4.0, it will be http://host:port/alfresco/cmisatom).
Repository ID: It is basically used to connect to a specific repository incase we have multiple repositories available. If we do not enter a repositoryId, then it will just look for the first repository using the given parameters and set it to that.


How To Setup A Liferay Cluster From Scratch?

We need to setup below properties in our portal-ext.properties(this is for one instance represented by 1p, same properties we need to add for second instance also represented by 2p) and some required IP addresses.

#cluster configurations - these settings are for cluster
net.sf.ehcache.configurationResourceName=/myehcache/hibernate-clustered.xml
dl.store.file.system.root.dir=/webapps/document_library_cluster
#other settings for cluster
liferay.home=/webapps/liferay-1p/liferay-portal-6.1.10-ee-ga1/
lucene.dir=/webapps/liferay-1p/liferay-portal-6.1.10-ee-ga1/data/lucene
cluster.link.enabled=true
lucene.replicate.write=true
multicast.group.address["cluster-link-control"]=239.255.4.1


How To Use AUI In Liferay? What Are The Advantages Of Using It In Liferay Instead Of JQuery Or Some Other JS Library?

AlloyUI (AUI) is Liferay's open-source javascript library. It is built on Yahoo User Interface (YUI) and has support for a variety of advanced javascript functions specifically designed for portlets. As it is Liferay provided JS library here no need to merge this code. It is designed to take advantage of and incorporate patterns from the best libraries to make building robust and flexible web applications. It is a JavaScript library, a CSS framework, a set of HTML recipes and a taglib library, all combined to empower developers across multi-skilled teams deliver rich and dynamic applications. Only we need to add certain tag library like below in order to use Liferay Alloy UI libraries.

<taglib>
        <taglib-uri>http://liferay.com/tld/aui</taglib-uri>
        <taglib-location>/WEB-INF/tld/liferay-aui.tld</taglib-location>
</taglib>

So further we can use these all form and fields like below in our JSP code.

<aui:form>
    <aui:input name="Name" size="45" />
</aui:form>


How To Use JQuery In Liferay?

We need to provide the entry like below in our JSP files. So that it can read the provided java script path very easily and we can use jQuery accordingly.

<script type="text/javascript" src="<%=themeDisplay.getPathThemeCss()%>/../js/jquery-1.7.2.min.js"></script>

How To Configure Liferay To Use A JNDI JDBC Datasource Instead Of Internal C3p0 Connection Pool?

We need to do the entry of perticular resource with some certain parameter like name, factory, driverclassname, url of database, uaername and password.
Below is the entry of resource where JDBC datasource is configured.

<Resource type="javax.sql.DataSource"
            name="jdbc/LiferayPool"
            factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
            driverClassName="com.mysql.jdbc.Driver"            
   url="jdbc:mysql://<IP-Address>/<database_name>?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false&amp;noAccessToProcedureBodies=true"
            username="liferay"
            password="0bknSWE2zzl"
            initialSize="10"
            maxActive="200"
            minIdle="0"
            />

Below is the entry of resource where c3p0.ComboPooledDataSource is configured.

<Resource
    name="jdbc/LiferayPool"
    auth="Container"
    type="com.mchange.v2.c3p0.ComboPooledDataSource"
    factory="org.apache.naming.factory.BeanFactory"
    driverClass="com.mysql.jdbc.Driver"    jdbcUrl="jdbc:mysql://<server-IP>/<database-name>?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false&amp;noAccessToProcedureBodies=true"
    user="liferay"
    password="0bknSWE2zzl"
    minPoolSize="10"
    maxPoolSize="100"
    />


I hope you find this list useful. Are you a Liferay developer? Feel free to suggest any questions we may have missed out on this list.

Related

Tips 6725672075438422900

Post a Comment Default Comments

...

item