Pages

Showing posts with label Liferay Interview. Show all posts
Showing posts with label Liferay Interview. Show all posts

Monday, April 2, 2012

Creating an extension environment in Liferay

Title : How to Create a extension environment in Liferay 




*An extension environment can be created from Liferay portal source
• The ext environment gives us complete control over the way the system behaves with ways to reconfigure default Liferay behavior
• release.adave.properties
• app.server.adave.properties
• ant clean start build-ext (takes 7-8 mins)
• ant clean deploy (takes 1-2 mins)
• Configure root.xml on tomcat to connect to database
• Run the app …

Using the plugins sdk in liferay

·         Plugins sdk can be used to create portlets and themes and deploy them to the Liferay portal



·         Easiest and fastest way to start building the enterprise portal application
·         Plugins  are hot deployed to tomcat
·
·          Plugins are fully JSR compliant and plugins developed outside sdk can also be used
*ant -Dportlet.name="hello-world" -Dportlet.display.name="Hello World " create
•ant -Dtheme.name="sample-theme" -Dtheme.display.name="Sample Theame “ Create
*ant deploy

Why use Liferay




  •  Need a portal based application
  • Need rapid development and / or prototyping (Well, most projects do !)
  • Need collaboration e-commerce,  internationalization

Thursday, March 29, 2012

Liferay Basics


Liferay is a portal server. This means that it is designed to be a single environment where all of the required applications (represented by individual portlets) can run, and these applications are integrated together in a consistent and systematic way.




Installing the social portlets


The social portlets are all included with the Liferay Community Edition distribution, but need to be installed separately for Enterprise Edition. If you're using Liferay Enterprise Edition, or had previously removed the social portlets from Community Edition, you can use Liferay's plugin installer to easily add social features to your portal.


If you're logged in as an adminstrator, go to the control panel, and in the Server section, click on Plugins Installation. From here, click on Install More Portlets and search for Social Networking. Once the results come up, select the latest version of the Social Networking Portlet, and then click Install. Once the install process finishes, you can start using the social networking portlets.

Social Networking with Liferay


Since the first social networks rose to popularity, concepts such as Friend and later Like--previously reserved for direct human interaction--have taken on new meaning in an always-online, information driven culture. It could be argued that social networks have transformed the way people interact with their friends, relatives, and colleagues. Friends, connections, followers, circles, and lists have enabled people to connect and stay connected in ways they'd never been able to before. Initially, these concepts proved to be highly successful for casual web sites but they didn't take to the business world as quickly. But now, more and more organizations are realizing the importance of leveraging social interactions for more than just recreation. Liferay's robust social features make it a great platform for business web sites, casual web sites, and everything in between.



Liferay has a constantly improving set of social features which enable you to encourage social interactions on your own portal, and to leverage the power and popularity of other social networks. In this chapter, we'll discuss:
  • General use social portlets
  • Social portlets for personal pages
  • Configuring personal pages for social networking
  • How to connect users using Liferay social relations
  • Social equity
  • Integrating Liferay with other social sites
When we're finished, you'll have a good idea how you can use Liferay to power your social network.

Purpose of portal-ext.properties


portal-ext.properties contains various configuration parameters. These settings

 can be modified or further settings can be added. For example, there is no existing section for database pool in portal-ext.properties but one can add the same as described in question 25.

What is inter portlet communication


Inter portlet communication (IPC) was introduced in JSR 286
More reading:



http://www.liferay.com/web/james.min/blog/-/blogs/241107
http://www.liferay.com/community/wiki/-/wiki/Main/Inter-portlet+communication

Difference between a Liferay Hook and Liferay EXT





Hooks is a feature to catch hold of the properties and JSP files into an instance of the portal as if catching them with a hook. Hookplugins are more powerful plugins that come to complement portlets, themes, layout templates, and web modules. A hook plugin is always combined with a portlet plugin. For instance, the portlet social-portlet is a portlet plugin for Social Office with hooks. In general, hooks would be very helpful tools to customize the portal without touching the code part of the portal. In addition, you would use hooks to provide patches for the portal systems or social office products.

EXT is used to customize and extend the Liferay portal. EXT builds a new ROOT webapp and replaces by a huge build mechanism your existing Liferay portal.
The Liferay EXT Environment is where you would ideally make changes to the portal itself. In other words, this is where you customize or “extend” the portal. You may ask, “Why can’t we just make the changes to the portal source directly?” The answer is that you technically CAN, but if and when you have to upgrade, you will have a tough time sorting out what is out-of-the-box and what is customized. EXT Environment keeps things separate.

Different languages in Liferay Themes.


 Different themes for Different languages in Liferay Themes

If you need different languages in your portal and also different theme based your language
Step 1 : Add languages portlet in banner. Using runtime in portal-normal.vm



Step 2: Write the css for align the languages portlet

Step 3:  Add these lines in portal_normal.vm


#if($locale == "RTL")
<link rel="stylesheet" href="$css_folder/rtl-custom.css" type="text/css"></link>
#else if($locale == "LTR")
<link rel="stylesheet" href="$css_folder/ltr-custom.css" type="text/css"></link>
#end


Step 4
rtl-custom.css,lrt-custom.css these both files having css related to body of theme. these files would place on css folder of your theme.

You need to apply css on body something as below 


body {
    background:url("../images/bg/body.jpg") repeat-x scroll left 90px #EEEEEE;
    font-size:10px;
    font-family:verdana,sans-serif;
    margin:0;
    padding:0;
}

 

Different languages in Liferay Themes.


 Different themes for Different languages in Liferay Themes

If you need different languages in your portal and also different theme based your language
Step 1 : Add languages portlet in banner. Using runtime in portal-normal.vm



Step 2: Write the css for align the languages portlet

Step 3:  Add these lines in portal_normal.vm


#if($locale == "RTL")
<link rel="stylesheet" href="$css_folder/rtl-custom.css" type="text/css"></link>
#else if($locale == "LTR")
<link rel="stylesheet" href="$css_folder/ltr-custom.css" type="text/css"></link>
#end


Step 4
rtl-custom.css,lrt-custom.css these both files having css related to body of theme. these files would place on css folder of your theme.

You need to apply css on body something as below 


body {
    background:url("../images/bg/body.jpg") repeat-x scroll left 90px #EEEEEE;
    font-size:10px;
    font-family:verdana,sans-serif;
    margin:0;
    padding:0;
}

 

Wednesday, March 28, 2012

Liferay Interview Questions


1) What are the various ways in which you can customize the default behavior of Liferay that ships to you?
2) What is the difference between a Liferay Hook and Liferay EXT?
3) Suppose I want to customize the behavior of Calendar portal that comes out of the box with Liferay, how can I do that?

4) How will you configure Liferay to authenticate users from LDAP?
5) What is inter portlet communication and how can that be achieved?
6) What is the difference between view and edit modes of a portlet?
7) What is service.xml and how will you use Liferay service builder?
8 ) Suppose I have a portlet written for Liferay 5.2.3 and I want to run it on Liferay 6, how can I do that? What if I get some spring and hibernate related exceptions with Liferay 6?
9) There is a requirement from the client that out of 4 portlets that you have written only 2 should be visible to a particular category of users. How will you achieve that? What if some fields in the remaining 2 portlets have also to be controlled based on user role?
10) What is the purpose of portal-ext.properties?
11) What steps will you follow to change the layout and theme of the portal pages?
12) Suppose I want to change the background color of the footer in Liferay, what steps should I follow?
13) Which JSR is being implemented by Liferay?
14) What improvements would you like to see in Liferay 6 portal?
15) There are 1000 users using the portlet developed by you, how will you take care of transaction management.
16) A client has two different portal applications for Sales and HR department. The client wants to run these portal applications on same server but with separate URL’s like http://<ip>:<port>/sales and http://<ip>:<port>/hr. How will you achieve that?
17) What are the minimum Java methods one needs to override in order to write a portlet?
18) How will you make the user to go from one JSP to another JSP page in a portlet?
19) While building a service using service builder, what is the purpose of specifying remoteservice=true in service.xml?
20) How to control the category in which the liferay portlet created by me will be displayed?
21) What is hot deployment feature of Liferay? Where will you place your portlets for them to be deployed without server restart?
22) Does Liferay support email notifications out of the box for portlets involving workflow?
23) What is the purpose of mode and persistence packages which are created by the Liferay service builder?
24) If there are 3 portlets and all of them need to talk to different database systems (say MysSQL, Oracle and SQL Server) because of some legacy appliation requirements. How will you make them connect to different databases?
25) Can you configure the database connection pool created by Liferay?
26) Can you list down various tools and frameworks used by Liferay? e.g. It uses Lucene for search
27) Suppose a client is pursuing a Liferay based solution to their requirements, what non-functional clarifications will you ask from the customer?
28) Is there a build number associated to a portlet assigned by the service builder? Where can we find the current build number?
29) Have you tried the Liferay 6 Eclipse plugin? What all limitations have you found?
30) How do you log events in a portlet? Do I need to configure Log4J for every portlet or is there a common place where one can configure Log4J so that all Liferay portlets can use logging API?
31) Do you know how to update your setup of Liferay 5.2.3 to Liferay 6?
32) Can I run my Struts 1.3 based legacy application as a portlet application? How?
33) Is it a good design to meet the customer requirements by creating a single portlet or splitting them into multiple portlets? What criteria will you use to split the functionality into multiple portlets?
34) What advantages do you see in running the Liferay portal application on a application server like JBoss than running it on a web server like Tomcat?

35) What all other portals have you heard of? How do you compare them to Liferay?
36) How will you implement i18 in a portal application? What if you want the user to choose his language preference?
37) There is a portlet application for managing images similar to Flickr. The user wants to see the images in full screen. Will Liferay allow you to do that?
38) I have a war file of the portlet which is created using service builder, what is the difference between pasting this war file in the deploy folder of Liferay and application folder of server (like webapps in case of Tomcat)?
39) How will you setup a clustered Liferay portal on 5 servers available to you?
40) How much user base can Liferay support without affecting performance?
41) There is a JRE shipped with Liferay package, do we not need a JDK and what is the purpose of bundled JRE?
42) Suppose there is a requirement from client to implement search functionality in Liferay portlet, does Liferay provides any API out of the box to support search?
43) What are the various ways in which one can override the default behaviour of Liferay?
44) The service builder can also build WSDL for you. What is the benefit of this feature provided by Liferay?
45) How will you build a portlet that can be added only single or multiple times in to the portal application?
46) Is it possible to set a session time out for a portlet which is different from other portlets and the Liferay portal?
47) What is the flow of HTTP request in Liferay?
48) The JSPPortlet.java extends  the MVCPortlet.java class. What purpose does MVCPortlet.java fulfill?
49) How do you perform Junit tests on your portlet? How do tackle the dependency on the MVCPortlet.java?
50) Is it mandatory to have the view logic in view.jsp? Can one configure some other JSP (say MyJSP.jsp) to be default view page than view.jsp?

What is Liferay




Liferay is an upcoming and  very famous open source solution for building portal based applications. If you are not familiar with what a portal then please visit iGoogle to see how a portal looks like. A portal is something which acts as container for various other smaller applications running as portlets within the portal container.
Coming to more details, Liferay offers various features to the application developer in order to meet the functionalities of the client in an easier way. For example, there is out of the box support for Chat, Message Boards, Calendar,Blog,Wiki, Document Management in Liferay. These features only a subset of all the features provided by Liferay.
In addition to these out of the box features provided by Liferay, these features can be customized to the extreme extent because of the open source nature of Liferay. The customization is made easy by providing hooks. Also, one can completely customize the look and feel of Liferay portal.
As Liferay doesn’t use EJB or JMS, it can be deployed an a servlet engine like Tomcat. The best part is that Liferay uses the latest technologies and tools to build the features. Some of the Java technologies used by Liferay include jQuery, VAADIN, Spring, Hibernate, Solr, Velocity, FreeMarker etc. This ensures best technologies are available to one when using Liferay.
Liferay also has a tool named Service Builder which helps in generating the helper code for interacting with databases. The databases supported by Liferay include HSQL,MySQL,MS SQL Server,Oracle,DB2 etc.
There are two versions of Liferay available. One is community edition which is free and the other is enterprise edition which has paid support. Since Liferay has strong user base, getting around the popular blockers is not that difficult. Enterprise edition should be used when professional consulting is required.

How Create Build and Deploy Liferay Portlets


A Liferay portlet is nothing but a web application consisting of Java classes, JSP, images, Javascript files. Here we will discuss the ways in which a Liferay portlet can be created.
There is an ANT script file which comes with the Liferay plugin SDK. This ANT script has various tasks for creating, building and deploying the portlet to Liferay server. All these ANT tasks can either be run using command line or by using Liferay 6 plugin for Eclipse. This Eclipse plugin also runs these ANT tasks behind the same. So its basically the ANT tasks that we want to run.


Creating Portlet:
The ANT command “create”, creates an empty portlet which is a web application having deployment descriptor web.xml inside the WEB-INF folder. There is also one JSP file named view.jsp being created which is the default first view of the portlet. In Liferay 6 plugin for Eclipse, we need to create a new Liferay Plugin project which also results in the creation of above described web application structure.
Meeting Functional Requirements:
To meet the functional requirements, one can write the view code in JSP. The database interaction code (business logic) can be written inside Java classes. This Java code can be either invoked using JSP scriptlets or JSP taglibs depending upon the size and requirements of the portlets. The DAO and DTO can be generated by using the service builder. The service builder reads service.xml and generates the Java classes for database CRUD operations.
The ANT task names “build-service” is responsible for generating the DAO and DTO code. With Liferay 6 plugin for Eclipse, there is a build service button displayed when service.xml is opened.
The service builder creates a JAR file of the generated code and places the same on CLASSPATH (inside lib folder of the portlet). After generating the DAO and DTO code, one can use them to write the business logic which includes the code required for interaction with database.
One more point worth mentioning is that the service builder only generates Java code and does not create the database tables corresponding to the entities mentioned in the service.xml. The database tables are created by the Liferay server after service builder has been run and portlet has been deployed. This means that the service builder creates entry somewhere inside the Liferay server so that the database tables can be created.
Deploying the Portlet:

The portlet is created and built inside the plugin SDK of Liferay. After writing the view code and business logic, it has to be deployed on to the Liferay server. The deployment is in the form of packaged WAR file. There is again one ANT task named “deploy” which compiles all the Java code and generates the WAR file which is then copied to Liferay server’s deployment folder (the folder named “deploy” present outside Tomcat, JBOSS etc.). The deploy ANT task can also be invoked from Liferay 6 plugin for Eclipse using the “Run on Server” feature of Eclipse.
Liferay server comes with Hot deployment feature which means that once the ANT task for deployment has run, the server detects the change and automatically loads the Liferay portlet application so as to make it available for use.
In this process of deploying the portlet, any required database changes are made by the Liferay server.

What is Liferay Portal


Portals can serve an enterprise in a variety of ways. Read about key use cases and then learn more about Liferay Portal's robust portal, content, and collaboration features.


Google Translator in a Liferay portal


People always prefer their native language for their convence. To browse a website with a feature of tranlsation is what most of them would like. Liferay provides a feature where in we can have our portal in different languages. This is achieved using  Language-ext.properties file.

But there are few drawbacks in using the above.
The  drawbacks are :
1.This requires a customisation in all the Language_xx.properties file. (For eg. If we want 30 languages option then 30 Language_xx.properties files need to be customised).

2.Even after doing so the entire portal is not changed to the language selected,only the variables mentioned in the  Language_xx.properties file are changed and anything from database is not changed.

So here is the convenient solution of having your portal in different languages by integrating the Google's API in two simple steps

Step1:

Copy and paste the below snippet code in the "portal_normal.vm" file


<div id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.
translate.TranslateElement({
pageLanguage: 'en',
layout: google.
translate.TranslateElement.InlineLayout.SIMPLE
}, 'google_translate_element');
}
</script>
<script src="//
translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

Step 2:
We can further change the position of the translate tab. To change the display mode in Horizontal, change the layout to
  layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL
For Bottom-right Position:    floatPosition: google.translate.TranslateElement.FloatPosition.BOTTOM_RIGHT
For Bottom-left Position:    floatPosition: google.translate.TranslateElement.FloatPosition.BOTTOM_LEFT

and so on..

To use the the Google's translator only in the selected sections of a website, we can use the below code
<script>
          function googleSectionalElementInit() {
new google.translate.SectionalElement({
sectionalNodeClassName: 'goog-trans-section',
controlNodeClassName: 'goog-trans-control',
background: '#99ff99'
}, 'google_sectional_element');
}
</script>
<script src="//translate.google.com/translate_a/element.js?cb=googleSectionalElementInit&ug=section&hl=auto"></script>

Add an element with a class name “goog-trans-section”  and a child element with class name “goog-trans-control”. On clicking the parent element, the contents within the child element will be translated.

Note: We can further customise the look and feel of the Google translator toolbar by strictly maintaining the Google trademark and logos.

The following are the merits and demerits of Liferay's translation and other translation APIs (eg. Google Translator)

Liferay's Translation
 Merits  1.Its looks professional
 2.Performance will not be affected.
 3.Translation of the content will be controlled by ourselves.

Demerits
 1.It will not translate Dynamic contents
 2.Static contents need to be mentioned in properties files manually
 3.The number of properties file increases as a number of language increases
 4.For CMS (i.e Web content and page navigations) we need to create articles in the                 respective languages seperately


Google and others Translation tools :
 Merits  1.No need of any properties file changes
 2.Dynamic content as well as static content will be translated in the respective languages
 3.For Web content and page navigations need not create articles in different languages
 4.Imlementation is easy. 
De Merits
  1.Performance issue.
 2.The translation control is handled by third party
 3.We need to adhere to the terms & condition of the third party
 4.We don't have control over any issues that are caused by the third party applications .

Theme and layout in liferay


1)Create a folder under plugins\themes\your-theme\docroot (e.g layout).
2)Add all the files Under your folder (e.g layout).
a.your_layout.tpl
b.your_layout.wap.tpl
c.your_layout.png
3)Add the files of your theme directly under the docroot/WEB-INF.
a.liferay-layout-templates.xml
4)Edit the file liferay-look-and-feel.xml present in the WEB-INF directory and add the following XML fragment.
<layout-templates>
<custom>
<layout-template id=" your_layout_Id" name=" your_layout_name">
<template-path>/layout/ your_layout.tpl</template-path>
<wap-template-path>/layout/your_layout.wap.tpl</wap-template-path>
<thumbnail-path>/layout/your_layout.png</thumbnail-path>
</layout-template>
</custom>
</layout-templates>
5)Then ant deploy from your theme level.


How to create liferay hook


Using hooks customizing jsp page of a existing liferay portlet. In this example I am taking portlet asset-publisher.

Step 1: Go to plugins/hooks create a folder with any name. eg asset-publisher-hook

Step 2: Go to asset-publisher-hook create folder docroot and build.xml file.

Content of build.xml should be like this:









Step 3:

Go to asset-publisher-hook/docroot create folder with name WEB-INF.

Step 4:

Now under WEB-INF create a file liferay-hook.xml and a folder with name jsps.

Step 5:

In liferay-hook.xml write following code.





/WEB-INF/jsps


Step 6:

Under jsps create folders html/portlet/portlet_name in our case portlet_name is asset-publisher.

Step 7:

Under portlet_name create the same structure for the page which we want to modify.

Eg. In asset-publisher we will try to modify full_content.jsp then structure will be

html/portlet/asset-publisher/display/full_content.jsp

Step 8:

Customize the jsp file.

Step 9:

Go to plugins/hook

Do ant deploy

Step 10:Check the changes on server

Recommended Tools For Liferay


The following instructions willhelp you get your development environment ready for working with the

source code. These instructionsare specific to setting up for deployment to Orion server and Tomcat 5.5


developing with Java JDK 1.5.Liferay Portal is compatible with Java 1.4 also and a wide array of

application servers andcontainers. You will need to adjust your development environment according to

your platform.

Before we can get started, thefollowing components must be installed on your machine.

3.1. JDK 1.5.0or JDK 1.4.2

1. Download and install JDK 1.5.0[http://java.sun.com/j2se/1.5.0/download.jsp]. JDK 1.4 is also

supported.

2. Set an environment variablecalled JAVA_HOME to point to your JDK directory.

3.2. Jikes 1.22or Jikes 1.21

Jikes is a Java compiler by IBMthat is much faster than the original one provided by the JDK.

1. Download and unzip Jikes 1.22[http://www-124.ibm.com/developerworks/oss/jikes]. If using JDK

1.4 you have to use Jikes 1.21instead.

2. Set an environment variablecalled JIKES_HOME to point to your Jikes directory.

3. Add JIKES_HOME\bintoyour PATH environment variable.

3.3. Ant 1.6.5

1. Download and unzip the latestversion of Ant [http://ant.apache.org/].

2. Set an environment variablecalled ANT_HOME to point to your Ant directory.

3. Add ANT_HOME\bin to your PATHenvironment variable.

3.4. Subversionor a Similar Version Control System

We recommend that you put allyour code and configuration files into a version control system.

Subversion is free and opensource and can be used through a set of commands, by installing a

subversion client such asSmartSVN [http://www.smartsvn.com/], TortoiseSVN [http://tortoisesvn.net/]

or through the integrationmechanisms provided by most IDEs.

Liferay UI Tabs

Creating Tabs is a really Cool feature and Liferay has an inbuilt functionality to do so.
Here is how it can be done.
1) In your Project , first create the following files under the following path
/docroot/jsps by creating a new folder called jsps
view.jsp
sunday.jsp
monday.jsp
tuesday.jsp
admin.jsp
code for view.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27


28
29
30
31
32
33
34
35
36
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<liferay-theme:defineObjects />
 
//A renderURL is created because we need to render a jsp page you need to use //renderURL we can also  pass parameters if required
 
<liferay-portlet:renderURL var="portletURL"/>
 
<%
//We must Specify a default value for tabs. In this example it is sunday. Else it //will throw an error.
String tabValue = ParamUtil.getString(request, "tab""sunday");
String tabsURL = "/jsps/" + tabValue.trim() + ".jsp";
String tabNames="Sunday,Monday,Tuesday" ;
String tabVal="sunday,monday,tuesday" ;
if(permissionChecker.isCompanyAdmin(themeDisplay.getCompanyId())){
tabNames+=",Admin" ;
tabVal+=",admin" ;
}
%>
 
<liferay-ui:tabs
names="<%=tabNames%>"
tabsValues="<%=tabVal%>"
param="tab"
url="<%= portletURL %>"
/>
 
//this wud render the tab page
<c:import url="<%= tabsURL %>"></c:import>

Here is how it would Look Like 


The Admin Page Will be Visible only if an Admin Logs in. 



To Download the Project click here