Sunday, October 16, 2011

Download and Install liferay

First download the community version with tomcat server from the liferay website
or Click Here

Unzip the contents to a suitable location.

Open the bin directory


And click on the startup.bat file to start and shutdown.bat file to shutdown.



To change the server standard time.

Open the setenv.bat in an editor and change the –Duser.timezone

-Duser.timezone=Asia/Delhi

Restart the Server .




For Database Settings

log into the MySql command line editor.

mysql> create database `lportal` CHARACTER SET utf8 COLLATE utf8_general_ci;

create a portal-ext.properties file in \liferay-portal-6.0.6

Add the following Lines to connect to MySql Database.

#
# MySQL
#
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEn
coding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=root

save and restart.

Check installation success in MySql

mysql>use lportal ;
mysql>show tables ;


A total of 185 rows indicating 185 tables must be shown.

There is another way to connect Tomcat to the database. Here is how it is done. Assuming that lportal schema is available in MySQL.

goto this path ${TOMCAT_HOME}\conf\Catalina\localhost
Open the root.xml and add the following lines in it.






while configuring your database do make sure the corresponding jar file of the database is present in the lib directory of tomcat. Liferay Bundled wit tomcat has mysql.jar in it by default in the lib/ext folder.
More Liferay 6.0.5 Properties.

Now ,some fine tuning must be done if you are going to start development in liferay , so that everything runs faster and smoother , without much of ui customization.

Here is what you've got to do.

Open setenv.bat again , and add the following lines to it

-Dexternal-properties=portal-developer.properties

Thats it, You are done and now you can start development on Liferay !!!

Liferay Permission Checker

Liferay-Permission Checker

Checking permission in liferay is just a matter of calling a function .


This function , is given the groupId , the name of the class , the primary key of the class and the type of Action supported.

We have defined all this in the default.xml file under the resource-actions folder.

The above permissionChecker , simply passes on these parameters and checks it against the permissions given to the particular user . If the user has permission it will return true , else false.

We have used the permission checker to toggle the Delete functionality for different users . Any user having role for which delete functionality has been granted permission . will see the delete icon , else wont.

Here is a screen shot displaying the permissionChecker in action , with 2 images of the portlet on before log-in and one after log-in.

Pre-Login .


Post-Login .


PermissionChecker API


Liferay Messages



SessionMessages and SessionErrors , are two classes which ease out sending out messages to the users or while debugging.

Few Uses of the liferay-error :



The message attribute contains the key to the key-value pair store in the Language.properties file.

Language.properties :
book-added=Books have been Added Successfully !
error-while-adding=Some Error has Occured While Adding, Please Try Again


If you click on Submit with all the fields empty , it will show you the above messages.




Cheers...!!

Gaurav Rastogi

Liferay Search Container

MVC Portlet Development : MVC Framework and AlloyUI

What we have done so far ,

Eclipse Installation

Directory Structure

Service Builder - I

Service Builder - II

and lets continue to the last part . The MVC Framework and Alloy UI


Every Portlet on a portal page , will have a different render and request cycle.

In servlet we either implement a doGet or a doPost method which handle the response and the request in the same cycle. But here in the Portlet specification jsr-286 , the request and rendering or response is handled separately.

In the Portlet cycle , we have two main methods processAction and render.

processAction handles all the requests and render handles the response.
When the portlet is loaded for the first time , render is called to load the default view lets say a form.When you fill the form and send it across processAction will be called to get all the form data.Once the processAction is executed you can specify a jsp page where the next event has to be handlded. By default it will go to the home page.

But in the MVCPorrlet interface , all these things have been abstracted for us. We donot need to implement any of these render or processAction methods.

In portlet.xml we specified view-jsp as n initial parameter.This is nothing but the location of the default page that loads when the portlet is loaded for the first time or whenever no action is called.

In MVC Portlet , there is a simple way of sending a request and rendering the response.

Below is the code of a JSP file and its corresponding MVC portlet.









In Portlet , we cannot create our own links, the way we do it in servlets . We need to create URLs to submit a form or to perform some action.

The above code , maps the to the function



in the BooksPortlet class.

The name in actionURL tag is the name of the function that is implemented in the portlet class. The var is just a variable holding the link.

So while creating a form , we specify it in the following manner .



Just like actionURL , we also have renderURL



It basically renders a jsp or an HTML page.


For rendering any JSP , MVCPortlet framework , has the above syntax.

For rendering after completing an action , we have



Calls to these functions , are followed by execution of the
Public void render(RenderRequest request,RenderResponse response) function internally.


BooksActionUtil.class

As you have seen in the BooksPortlet , we have called two functions ,



This is a standard procedure followed by Liferay , to reduce concentrating all the code in one class itself. Like common , it follows more out of practise and common sense. So here , are the two classes , BooksActionUtil.class and BooksValidator.class



BooksVaildator.class



ThemeDisplay



themeDisplay is an object containing all the information about the page, its layout, about the user whether he is logged in or not , certain fixed urls like create account , sign in etc. from themeDisplay we can get information about the company,group,user the particular page is associated with. It’s a very important object.

Here is the documentation of the ThemeDisplay Object and its functions.

Here is the Screen Shot of the portlet that we have created.


DatePicker

The date picker object Is very simple to implement. Here is the implementation code.



For the date picker , it is necessary to provide the Model and the bean attributes to the input tag.

In the src/META-INF folder , we have a xml file where we can set restrictions on the datatypes
portlet-model-hints.xml




We can also restrict the lenth of certain fields using



For more info on model-hints , take a look at the liferay source code ,
portal-impl/src/META-INF/portal-modelt-hints.xml file.

Model-Hints


NOTE : While using the date field , the name attribute of the input tage should match with the name attribute of the field tag in portlet-model-hint.

ParamUtil and PortalUtil.

ParamUtil is a utility class provided by liferay to extract the parameters from the query strings with a lot of added functionality.
For Example :


Here the getString method is having 3 parameters, request object ,the parameter name , and the default parameter if in case there is an error in the connection or the session is timed out.

ParamUtil Documentation .

PortalUtil is also a utility class having some portal related functions

Liferay Also provides a Validator class , which we can use to validate all predefined java primitives and objects.
Life email address,phonenumber , street address , null check etc.

Validator Documentation


Liferay-Search Container

Liferay provides yet another awesome feature of generating a tabular container , with navigation capabilities.
Its also pretty simple to implement. You just needs the list of Object that needs to be displayed.That object can either be Model class or our Own bean class.




In the tag , we first populate the list . It counts the number of elements.

this tag , is used to display the all the information , But we must make sure to give the correct class name and the primary key

Note : Make sure you specify your "className", "keyProperty" name exactly the way you have written in service.xml, It is case-sensitive , and the "modelVar" is just a variable name, You can name it whatever you want just make sure that name doesnt repeat throughout the entire jsp document.



You might come across a situation where the data in your column is not matching the UI requirement , Like for Example , you store the date in 1970,11,11 and now you want to format this date before you put it up on search-container , how to go about that ?

Simple , Just create a new Class , and just to follow proper naming convention , post-fix the class name with "Bean"
Then create instance variables , of the class same as that in service.xml , you can also give them different names

For Example , for the books portlet ,



then refer modelClass=com.package.name.BooksBean and the keyProperty=bookId or whatever you have chosen in your beanClass.

Also while populating the List donot forget to map each property of Bean to the Actual Class



More About Search-container.Click Here


Also look into Liferay Permission Checker.

LIferay UI TABS

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



Here is how it would Look Like


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




Click Here to download this Project.


Cheers..!!

Gaurav Rastogi

Liferay UI Taglib Features-II

Few more UI TagLibs defined by liferay which can be used in your jsps.

Liferay-UI Panel




Liferay Text Area




Liferay Time Select




Liferay Text Editor






Cheers..!!

Gaurav Rastogi

Liferay UI Taglib Features-I


Customizing liferay Using Trick-II

1) How to change the domain name from liferay.com to example.com

Company Properties

company.default.web.id=liferay.com

change it to example.com

2) How to change my login ? If i want to use screen name instead of emailAddress

company.security.auth.type=emailAddress
#company.security.auth.type=screenName
#company.security.auth.type=userId

In the above case , screenName and userId are commented out using #

3) Password Related
Set this to true to allow users to ask the portal to send them their password.
company.security.send.password=true

Set this to true to allow users to ask the portal to send them a password reset link.
company.security.send.password.reset.link=true

Set the following encryption algorithm to encrypt passwords. The default
algorithm is SHA (SHA-1). If set to NONE, passwords are stored in the
database as plain text. The SHA-512 algorithm is currently unsupported.

#passwords.encryption.algorithm=CRYPT
#passwords.encryption.algorithm=MD2
#passwords.encryption.algorithm=MD5
#passwords.encryption.algorithm=NONE
passwords.encryption.algorithm=SHA
#passwords.encryption.algorithm=SHA-256
#passwords.encryption.algorithm=SHA-384
#passwords.encryption.algorithm=SSHA

Uncomment whichever password encryption algo you would like http://www.blogger.com/img/blank.gifto use

Set your own regex pattern for your Password
passwords.regexptoolkit.pattern=(?=.{4})(?:[a-zA-Z0-9]*)


Set this to true to allow the user to choose a password during account creation.
login.create.account.allow.custom.password=false

More Password Properties

Cheers..!!
Gaurav Rastogi.

Monday, October 10, 2011

Customizing Liferay using Tricks-I


Liferay Plug-In Project Tutorial

1. Now that a SDK and portal server have been configured you can create a new Liferay plug-in project. Go to File > New Project... > Liferay > Liferay Plug-in Project


2. In the Liferay Plugin project wizard page, select the SDK and Liferay runtime and then select the plug-in type (portlet is default) and now you can create a new plug-in project, by clicking Finish.
3. If it worked you should see a new plugin project in the package explorer, so you are ready to begin Plugin Development.


Cheers..!!

Gaurav

Liferay Portal Tomcat Runtime / Server Setup

1. In eclipse open the Runtime environments preference page (Go to Window > Preferences > Server > Runtime environments)

2. Click Add to add a new Liferay runtime and find Liferay v6 Tomcat under the Liferay, Inc. category and click Next.

3. If you have not already downloaded and installed a copy of the Liferay Portal Tomcat bundle then you can download the latest Liferay Portal Tomcat bundle by clicking the "Download and Install..." button within the wizard.

4. If you used the download option you can skip this step, if not, click Browse and select the location of the liferay-portal-6.0.2 directory.

5. Once you have selected the Liferay portal directory if it has a bundled JRE then that bundled JRE will be automatically selected as the JRE to use for launching the server. However, if there is no bundled JRE (Mac and Linux users) then you will need to select the JRE to use for launch.

6. Click finish and you should see the Liferay portal runtime in the list of runtimes in the preference page.

7. Click OK to save the runtime preferences.
8. If you didn't choose to create a server you will need to create one from the servers view before you can test the server.
9. Find the Liferay, Inc category and select the Liferay v6 Server and choose the Liferay v6 Runtime that you had previously created.


Testing the Liferay portal server #

1. Go to the servers view and you should see the new server that was created. right click and choose "Start" or "Debug"

2. You should see messages appear in the Console view and once it starts, the servers view will update to show that it is "Started" and then, right-click the server and select the (Liferay Portal > Open Portal Home) action.


3. The eclipse browser should open to the portal home at http://localhost:8080


Cheers..!!

Gaurav

Liferay IDE Getting Started Tutorial

Table of Contents [-]

Installation #

If you have not already installed Liferay IDE view Liferay IDE Installation Guide for a detailed walk-through of installation.

Requirements before getting started #

1. Liferay Portal 6.0 (RC2 or greater) downloaded and installed (or download in the IDE itself)
2. Liferay Plug-ins SDK 6.0 (RC2 or greater) downloaded and installed (or download in the IDE itself)
3. Eclipse Helios/Galileo Java EE for developers package -
see the Liferay IDE Installation Guide for more information.

Note: earlier versions of Liferay, e.g. 5.x, are not supported yet by the Liferay IDE



Liferay Plug-ins SDK Setup #



Before you can begin creating new Liferay plug-in projects, a Liferay Plug-ins SDK and Liferay Portal must be installed and configured in the IDE.

1. Open Eclipse with Liferay IDE installed.
2. Open Preference page for Liferay > Installed SDKs ( Go to Window > Preferences > Liferay > Installed SDKs )


3. If you have not already downloaded the Liferay Plug-ins SDK for your portal version you can download it from the sourceforge.net Liferay downloads page. Liferay plugin sdk is located available in the "portal" folder. In the "portal" folder, select the Liferay version matching the Liferay version. Within this folder, look for liferay-plugins-sdk-x.x.x.zip (usually the last file).
4. Add your SDK using the Add button which brings up the Add SDK Dialog:

5. Browse to the location of your Plug-ins SDK installation.
6. The default name is the name of the directory but you can change it if you wish.
7. Select OK and you should see your SDK in the list of Installed SDKs.

Note: multiple SDKs can be added to the preferences but you will need to select at least one SDK to be the default which is represented by the SDK that has the checkbox selected.

Note: if you have version 6.0.4 of Liferay Portal and the Plugin SDK, you will need to change your build.properties file. The SDK plugin assumes you have installed the SDK at the same level (same directory) as the portal directory. In the line

app.server.dir=${project.dir}/../bundles/app_server_name of build.properties you have to change bundles with the name of the Liferay portal installation directory e.g. liferay-portal-6.0.4.
Otherwise, portlets created with the SDK plugin will not be deployed by Ant.

Note: multiple SDKs can be added to the preferences but you will need to select at least one SDK to be the default which is represented by the SDK that has the checkbox selected.

Note: if you have version 6.0.4 of Liferay Portal and the Plugin SDK, you will need to change your build.properties file. The SDK plugin assumes you have installed the SDK at the same level (same directory) as the portal directory. In the line

app.server.dir=${project.dir}/../bundles/app_server_name of build.properties you have to change bundles with the name of the Liferay portal installation directory e.g. liferay-portal-6.0.4.
Otherwise, portlets created with the SDK plugin will not be deployed by Ant.

To Continue see: Liferay Portal Tomcat Runtime / Server Setup

Cheers..!!
Gaurav

Liferay IDE Installation Guide

This document is a detailed guide to installation of Liferay IDE.

Requirements #

Java 5.0 JRE
Eclipse Inidigo (3.7.x) or Eclipse Helios (3.6.x) IDE for Java EE Developers

Installation steps #

1. Install Eclipse Indigo or Helios (unzip download file from above)
2. Run eclipse.exe
3. When eclipse opens, go to Help > Install New Software...


4. Click "Add..." button to open Add Site dialog
5. Type in Liferay IDE for name, and location use one of the following URLs


Eclipse Indigo Update sites #

Indigo release stable URL - http://releases.liferay.com/tools/ide/eclipse/indigo/stable/]

Indigo release nightly URL - http://releases.liferay.com/tools/ide/eclipse/indigo/nightly/] (Unstable version)


6. Select OK
7. Select the Liferay IDE site from the combo selection box.
8. When the table refreshes you should see Liferay Tooling category and one entry for Liferay IDE feature, select the checkbox to install the feature.



9. Click Next and then click Finish to begin the install
10. After plugins download and install you will have to accept that the content is unsigned and then restart eclipse.
11. After you restart, go to Help > About Eclipse and you should see a Icon badge for Liferay IDE that shows you have it properly installed.



Check installation #

If everything installed correctly you should be able to begin using the IDE.


Cheers.

Gaurav

Download and Install liferay

First download the community version with tomcat server from the liferay website
or Click Here


Unzip the contents to a suitable location.

Open the bin directory


And click on the startup.bat file to start and shutdown.bat file to shutdown.



To change the server standard time.

Open the setenv.bat in an editor and change the –Duser.timezone

-Duser.timezone=Asia/Delhi

Restart the Server .




For Database Settings

log into the MySql command line editor.

mysql> create database `lportal` CHARACTER SET utf8 COLLATE utf8_general_ci;

create a portal-ext.properties file in \liferay-portal-6.0.6

Add the following Lines to connect to MySql Database.

#
# MySQL
#
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEn
coding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=root

save and restart.

Check installation success in MySql

mysql>use lportal ;
mysql>show tables ;


A total of 185 rows indicating 185 tables must be shown.


Thats it, You are done and now you can start development on Liferay !!!



Cheers..!!

Gaurav