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.