Login in Liferay with Facebook Account


In most of the websites you see that their is a option by which you can login with your facebook credentials. Today we will achieve this Login Functionality with Facebook in our Liferay. This consists of two Major Steps.

1)Create Facebook App
2)Integrate this App with Liferay.

So lets start step by step:-

A)Create Facebook App

Go to facebook Developer site by clicking here . And login with your facebook credentials.Now Click on MyApps and than click Add a New App. A pop up is open click Facebook Canvas as:-



When you click on Facebook canvas a new window is open Click Skip and Create App ID as:-



Now provide your app name , namespaces(must not contain space) and category and Click App ID.



Than a Security Check pop up is open which test you that you are a human and not robot. In my case it will ask to select flowers:-



Select flowers and Click Submit.

Now your app is created .Now Click to settings:-



Now Click on Add Platform a pop up is open select website:-



Now Provide the site url of your website and your email id:-



and Click Save Changes.

Now your App is created. Now make it public by Clicking on Status and Review.Change No to Yes and Click Confirm.





B)Integrate App with Liferay
Now Click on Control Panel-->Portal Setting -->Authentication and Select Facebook as:-



Provide Application ID and Application Secret and tick enabled Now Click Finish.


Check Output

Now Sign Out and Click on Sign In button. You will see a new option facebook .


Click on that you will redirect to facebook login page enter your credentials and you will be able to login in Liferay with facebook.

Note:- You can do Step B with liferay 6.2 but their is a issue in liferay 6.2, you will be redirected to blank page .When you refresh that page than able to login . You can check this issue here

Hope this will Help....






Related Post:-

Custom Field/Attribute or Expando in Liferay Programmatically


We already know how to create custom field using control panel . 
Lets consider a scenario we create 40 custom fields in our local server using control panel . When i deployed my application to production server we need to create all custom fields again in production server . What if as soon as our application start and all custom fields create automatically????


Today we will create same custom field married in User entity which contain boolean value Programmatically . For this we use Event hook in Liferay. So before reading this blog it is highly recommended to read my previous blogs on Custom Fields  and  Event hook in liferay.

So lets start step by step:-

Step 1:-Create Liferay project
File-->New-->Liferay Plugin Project-->Provide name-->Select hook in plugin type-->Finish.




Step 2:-Create  hook inside project
Right click on project-->New-->Liferay hook Configuration-->tick portal.properties-->Next.




then a pop up is open.Add a new event application.startup.events and add a Class which is called on application start.




Step 3:-Check Generated Code
By using eclipse ide portal.properties file automatically created as:-

portal.properties
and liferay-hook.xml as:-

liferay-hook.xml

Step 4:-Provide Code for Custom field Creation
Open CustomFieldsCreations.java from package com.test and paste this code:-

CustomFieldsCreations.java


Explanation:-

  • run method is called when ever application starts.
  • addExpandoTable method check if table already exists than do nothing otherwise create a new table with name  CUSTOM_FIELDS.
  • addExpandoColumn method check if table CUSTOM_FIELDS contain a column with name married if yes do nothing otherwise create new column .
  • addCoumn method of ExpandoColumnLocalServiceUtil take 4 parameters tableId, Column name, type of field here we use boolean and default value which i take as unmarried ie false.

Step 5:-Check Output
Open database and check tables expandotable and expandocolumn.
Or you can go to control panel and check a new custom field is added in User entity.

Project Structure


Java Portlet Specification (JSR 168 vs JSR 286)


Initially portal vendors had their own portlet frameworks but the problem is those portlets are specific to portal Server and cannot be deployed to another server.So their is specification or we can say Standards for portlet development. By using those standards you can write a portlet which can be run on all compliant portlet Containers.



Their  are basically two JSR standard for portals:-

1)Java portlet specification 1.0 ie JSR-168

JSR-168 released in 2003 and give standards for :-

  • Portlet API.
  • Portlet Taglib
  • Portlet Life Cycle
  • Window States
  • View Prefrences


This specification introduced two phases:
  • Render Phase
  • Action Phase



2)Java portlet specification 2.0 ie JSR-286

This specification introduced two extra phases so now we have 4 phases:-

  • Render Phase
  • Action Phase
  • Event Phase for IPC
  • Resource Serving phase for Ajax calls.

Features in JSR-286:-

1)Portlet filter is introduced .
2)Annotation support in Generic portlet.
3)Generate non mark up content like images, pdf using Resource serving phase.
4)Interportlet Communication is easily handled using Events.


Hope this will Help....





Related Post:-

Database Migration From Liferay 6.1 to Liferay 6.2


Today we will discuss how to migrate database (users, roles,pages, webcontent etc) from Liferay 6.1 to Liferay 6.2. I assume that you already installed Liferay 6.1 and created pages , roles and user. The name of the database we are using for liferay 6.1 is named as liferay6.1db.

So lets start this step by step:-


Step 1:-Take backup of your database
As a precaution take backup of your database ie liferay6.1db so that if anything goes wrong your have your original database.

Step 2:-Install liferay 6.2 with hypersonic
Install liferay 6.2 and use hypersonic databse which is provided by liferay.

Step 3:-Replace document library folder
Now copy content from document_library folder of liferay 6.1 (..\liferay-portal-6.1.2-ce-ga3\data\document_library) and paste in liferay 6.2(..\liferay-portal-6.2.0-ce-ga1\data\document_library).

Step 4:-Change portal-ext.properties
Now open portal-ext.properties file and point database entry to liferay 6.1 database ie liferay6.1db.

You have to change algorithm also which is used in liferay 6.2



Step 5:-Restart the Liferay 6.2 Server
Now restart your server .You can see migration activity on the console of your tomcat . Thats it your database migrated successfully from liferay 6.1 to 6.2.

By using this approach you can migrate:-

  • User
  • Roles
  • Pages
  • Structures and Templates
  • Web Content.



Note:-  

If this error comes:-

Then open data base table portletprefrences and change NULL to some text like "Change to Not Null by me"

And Restart Server.




Hope this will Help....


Related Post:-

Quartz Scheduler in Liferay


Today we will discuss about Schedular in Liferay. Sometime we have a situation in which we have to perform a task repeatedly after a certain period of time.Ex- Send a mail every week.

Liferay provide a simple way to achieve this.We create schedular class and provide entry of timing in liferay-portlet.xml. Time for schedular can be define by 3 ways:-

1)Using Liferay Feature

Ex-   <simple>
<simple-trigger-value>1</simple-trigger-value>
<time-unit>minute</time-unit>
</simple>  

Here in time unit we mention minute and in simple trigger value we mention 1 .This means this job run in each minute.

2)Using Property file

Ex- <cron>
<property-key>everyThirtySecond </property-key>
      </cron> 

We define key and cron expression in portlet.properties file like everyThirtySecond = 0/30 * * * * ?

3)Using Cron Expression Directly

Ex- <cron>
        <cron-trigger-value>0/15 * * * * ?</cron-trigger-value> 
       </cron>

This job runs in every 15 seconds.

Note:- For Cron Trigger Expression you may refer here.

So lets start this step by step:-


Step 1:-Create Liferay Project and Portlet
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as schedular and click finish. After that Right Click on your project and click on New than click on Liferay Portlet. Provide class name as Demo and select MVCPortlet and click finish.

Note:-You can check the snapshots in my  blog on Portlet Configuration Page in Liferay.



Step 2:-Create Schedulars
Inside com.test package create 3 classes that implements MessageListener inteface and provide the definition of receive method.

FirstSchedular.java



SecondSchedular.java



ThirdSchedular.java



Step 3:-Provide timing in liferay-portlet.xml
Open liferay-portlet.xml and paste this:-


Explanation:-
Here we provide the entries of all 3 Schedulars.



Step 4:-Create portlet.properties
Inside docroot/WEB-INF/src create portlet.properties and paste this:-

everyThirtySecond = 0/30 * * * * ?

because second schedular take value from property file.





Step 5:-Check output
Deploy the portlet and add to page:-


Now check eclipse console




Project Structure









Hope this will Help....

You can Download Source code from  Schedular in Liferay.


Related Post:-

Send Redirect in Liferay


Today we will discuss how to redirect from a portlet to another portlet which are placed on some other page. For this we need two things:-

1)Portlet Layout Id(plid)
We need the plid of the page where we want to redirect.We can get the plid by the page name as:-



2)Portlet Name
We can get the Portlet name (on which we have to redirect) by clicking on wheel icon of portlet than go to look and feel and than click on advance Styling.




So lets start this step by step:-


Step 1:-Create Liferay Project and Portlet
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as send-redirect and click finish. After that Right Click on your project ie send-redirect and click on New than click on Liferay Portlet. Provide class name as Demo and select MVCPortlet and click finish.

Note:-You can check the snapshots in my  blog on Portlet Configuration Page in Liferay.


Step 2:-Change view.jsp
Open view.jsp and paste this content:-


Explanation:-
Here we create a simple form on submit of form sendAction method is called inside controller.


Step 3:-Create Second Portlet
Right Click on project and click on New than click on Liferay Portlet.Give Portlet Name as Result and also change jsp name to result.jsp.


Step 4:-Deploy Result Portlet
Deploy the Result portlet and add to any page in my case i am adding this to a public page named about. Now get the Portlet name by going to look and Feel as discussed above. In my case the portlet name is result_WAR_sendredirectportlet.



Step 5:-Change Controller of Demo Portlet
Open Demo.java and Paste this Content:-


Explanation:-

  • Here first we get the plid and than create a URL and send redirect to another page using plid.
  • we also send a parameter so that this can be used in another portlet.
  • For more detail on LayoutLocalServiceUtil you may refer my blog add Portlet and Change Layout Programmatically.

Step 6:-Change result.jsp
Open result.jsp and paste this:-


Explanation:-
Here we just print the value that is set in Demo.java .



For Output


Now deploy both Demo and Result portlet and add Demo Portlet to welcome page and Result Portlet to about page .

When you click on submit it will redirect to Result Portlet which is placed on about page.


Project Structure



Hope this will Help....

You can Download Source code from  Send Redirect in Liferay.











Related Post:-

Inter Portlet Communication(IPC) in Liferay


Inter Portlet Communication ie IPC is needed when we have to communicate between two portlets. Some times these portlets are on same page sometimes they may be on different page. 

Example:- We have a drop down in one portlet by which we can select country name and another portlet display the currency, states, national flag, climate on the basis of country selected by first portlet. In this case we have to send value from first portlet to another.


We can achieve IPC by following ways:-

1)IPC using Portlet Session
IPC by Portlet session work for both scenario ie Sender and Receiver portlet are on same page or different page. You can read more in my blog IPC by Portlet Session.


2)IPC using Public Render Parameter
IPC by public render parameter work if both portlet are on same page. But by adding one property in portal-ext.properties:-

portlet.public.render.parameter.distribution=layout-set

You can add portlet on different page also.For more detail you can read IPC using Public Render parameter.


3)IPC using Events
Events is introduced in Portlet 2.0  by which you can do IPC in very easily. Here the two portlets are on same page only. For more details you may refer IPC using Events.


4)Client Side IPC
Liferay provide two methods one for Sender(Liferay.fire) and one for receiver(Liferay.on) by which you can achieve IPC. In this case portlets must be on same page. For More details you may read  Client Side IPC in Liferay.





Hope this will Help....


Related Post:-

Client Side Inter Portlet Communication in Liferay


Today we will discuss Client Side Inter Portlet Communication in Liferay . In my opinion it is the simplest way for sharing data between two portlets which are on same page. Liferay provide two basic methods for this:-

1)For Client

Liferay.fire('eventName',{
            parameter1: value1,
            parameter2: value2

    });

2)For Receiver

 Liferay.on('eventName',function(event) {
   var firstValue = event.parameter1,
   var  secondValue = event.parameter2

});

Note:- Their may be one sender and many receiver but sender and all the receiver are must be on the same page . 

We take a simple scenario where user can select food type from one portlet and second portlet shows food items on the basis of first portlet.Here we create two project and each project contain one portlet.

So lets start this step by step:-

For Sender

Step 1:-Create Liferay Project and Portlet
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as client-side-sender and click finish. After that Right Click on your project and click on New than click on Liferay Portlet. Provide class and package name and select MVCPortlet and click finish.

Note:-You can check the snapshots in my  blog on Portlet Configuration Page in Liferay.



Step 2:-Change view.jsp 
Open view.jsp and paste this:-


Explanation:-

  • On click of button we fetch the value of selected radio button and set in foodType.
  • We give the eventName as selectedFoodType which is used to fetch the data in receiver.


Note:-Change <requires-namespaced-parameters> is false inside liferay-portlet.xml.






For Receiver

Step 1:-Create Liferay Project and Portlet
Similarly as in Sender Create project with name client-side-sender and create a portlet in it.



Step 2:-Change view.jsp
Open view.jsp and paste this:-



Explanation:-
Here we get the value from event and on the basis of input we show the output.


For Output


Now deploy both sender and receiver portlet and add to same page .



Now Select Vegetarian and click submit



Select Non-Vegetarian and click submit




Inter Portlet Communication (IPC) using Events in Liferay


We already know IPC using public render parameters  .Today we will see how to do IPC using Events. Events based IPC was introduced in JSR 286 or we can say in Portlet 2.0. According to this a new method processEvent introduced in Life Cycle of Portlet.Here one Portlet can Produce a event which can be consumed by other portlets.

We take a simple scenario where user can select food type from one portlet and second portlet shows food items on the basis of first portlet. This is a Sender, Receiver kind of scenario but for events there may be one sender and multiple receivers.Here we create two project and each project contain one portlet.

So lets start this step by step:-


For Sender

Step 1:-Create Liferay Project and Portlet
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as event_sender and click finish. After that Right Click on your project ie event_sender and click on New than click on Liferay Portlet. Provide class and package name and select MVCPortlet and click finish.

Note:-You can check the snapshots in my  blog on Portlet Configuration Page in Liferay.


Step 2:-Change portlet.xml
Open portlet.xml and enter supported publishing event as:-


Explanation:-
Focus on these lines:-

<supported-publishing-event>
                <qname xmlns:food="http://aditya/events">                                                 food:foodType  
               </qname>
</supported-publishing-event>

Here Supported Publishing event tell that this portlet can generate event with name foodType. The Qualified name(qname) is used so that parameter name space properly to resolve conflict in case where portlet have two events with same name.



Step 3:-Change view.jsp
Open view.jsp and paste this content:-

Note:- We are not using namespaces, so set required namespace parameter property is false in liferay-portlet.xml.


Step 4:-Change the Controller
Open your Controller and paste this:- 



Explanation:-
Here we fetch the Qname from portlet.xml and produce a event.



For Receiver

Step 1:-Create Liferay Project and Portlet
Similarly as in Sender Create project with name event-receiver and create a portlet in it.


Step 2:-Change portlet.xml
Similarly as in Sender change  portlet.xml .After Security-role-ref tag paste this:-

<supported-processing-event>
     <qname xmlns:food="http://aditya/events">                                                 food:foodType
        </qname>
 </supported-processing-event>

Note:- In Sender we use supported publishing event but in receiver we use supported processing event.


Step 3:-Change the Controller
Open your Controller and paste this:-

Explanation:-
1)By using the annotation @ProcessEvent we can create method with any name otherwise we have to use default processEvent method.
2)Here First we get the event and than value from the event which is set by sender portlet .
3)Finally we set value in request so that it can be get in view.jsp


Step 4:-Change the jsp
Open view.jsp and paste this :-

Explanation:-
Here we get the value that is set in Controller and on the basis of condition show different messages.

Note:- We are using jstl tage here so provide entry in liferay-plugin-package.property file as:-






For Output


Now deploy both sender and receiver portlet and add to same page .



Now Select Vegetarian and click submit



Select Non-Vegetarian and click submit



Note:-Now if you want to add the portlet on different pages . Better you use session or Public render Parameters for IPC because when processEvent method completes in receiver it called doView.
So when portlet is on some other page and you click on navigation bar to change the page only doView of receiver portlet is called and not processEvent.

Inter Portlet Communication (IPC) using Public Render Parameter in Liferay


We already know that render Parameter set in processAction is available to render method of same portlet. But if we set render parameter in one portlet and want to get in another portlet . In this case we use Public Render Parameter so that parameter set in one portlet can be available to another Portlet.This feature is known as Inter Portlet Communication(IPC)  using Public Render Parameter.

We take a simple scenario where user can select food type from one portlet and second portlet shows food items on the basis of first portlet. This is a Sender, Receiver kind of scenario.Here we create two project and each project contain one portlet.

So lets start this step by step:-


For Sender

Step 1:-Create Liferay Project and Portlet
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as prp_sender and click finish. After that Right Click on your project ie prp_sender and click on New than click on Liferay Portlet. Provide class and package name and select MVCPortlet and click finish.

Note:-You can check the snapshots in my  blog on Portlet Configuration Page in Liferay.

Step 2:-Change portlet.xml
Open portlet.xml and enter supported public render parameter tag and public render parameter tags :-

Explanation:-
Here we set two things:-

1)Tell Portlet that we are using public render parameter as:-
          
         <supported-public-render-parameter>
                            foodType
          </supported-public-render-parameter>

2)Use Qualified name(qname) so that parameter name-spaced properly to resolve conflicts.
          
         <public-render-parameter>
         <identifier>foodType</identifier>
                <qname xmlns:x="http://aditya/public">
                         x:foodTypeParam
                  </qname>
         </public-render-parameter>


Step 3:-Change view.jsp
Open view.jsp and paste this content:-


Note:- We are not using namespaces, so set required namespace parameter property is false in liferay-portlet.xml.

Step 4:-Change the Controller
Open your Controller and paste this:-

Explanation:-
Here we just fetch the value from jsp and set in render Parameter.


For Receiver

Step 1:-Create Liferay Project and Portlet
Similarly as in Sender Create project with name prp-receiver and create a portlet in it.


Step 2:-Change portlet.xml
Similarly as in Sender change  portlet.xml of Receiver as:-



Step 3:-Change the Controller
Open your Controller and paste this:-

Explanation:-
Here we get the value from render parameter and set in attribute so that we can use this on jsp.

Step 4:-Change the jsp
Open view.jsp and paste this :-


Explanation:-
Here we get the value that is set in Controller and on the basis of condition show different messages.

Note:- We are using jstl tage here so provide entry in liferay-plugin-package.property file as:-







For Output


Now deploy both sender and receiver portlet and add to same page .



Now Select Vegetarian and click submit



Select Non-Vegetarian and click submit



Note:-Now if you want to add the portlet on different pages .You need to provide a entry in portal-ext.properties as:-

portlet.public.render.parameter.distribution=layout-set








Hope this will Help....

You can Download Source code from  IPC using Public Render Parameter.

Related Post:-