Wednesday 7 November 2012

Customizing Liferay Classes using ext plugin in 6.1

Liferay is highly flexible that developers can override any Liferay class by just replacing them in Ext Plugin. But overriding is not a very good action considering "Open for extension closed for Modification" Principle. 
so in this blog post I am going to show simple steps how to extend a Liferay class. 

Note: use ext plugin  class extension or replacement as a last resort if and only if the same cannot be achieved through hooks or other ways.

Step 1: Create you class by extending the Liferay class.
Step 2: Create a file called ext-spring in folder docroot/WEB-INF/ext-impl/src/META-INF
Step 3: From Liferay source code get the file portal-impl/src/META-INF/portal-spring.xml
Step 4: just copy the bean class you are extending from portal-spring.xml and paste to your ext-spring.xml, change the class name to your new extended class. (please ensure you have the <beans> outer tag too in ext-spring as in portal-spring)
step 5: deploy your ext, now Liferay will call your class instead of its own implementation.

Monday 5 November 2012

Adding JQuery Library to Liferay 6.1 at Portal level

As all Liferay developers know, Liferay 5.2.x and earlier had included jQuery library by default at Portal level, so if we want to use jQuery in any portlet or plugins, we do not need to include the library. But from 6.0, Liferay is using YUI, so jQuery is not available by default and we need to include the jQuery library if we want to use.

The following blog entry from Liferay covers three different ways to include jQuery

http://www.liferay.com/web/nathan.cavanaugh/blog/-/blogs/5363997

1. Theme Level
2. Portlet Level
3. jsp level.

but I came across one scenario where we wanted to have the same behavior as in 5.2.3, we have multiple themes so we do not want to duplicate same code in every portlet, and want to include the jQuery at portal level..

The solution worked for us is

Step 1: included the jquery-1.2.6.min.js in your hook - /jsp-hook/docroot/WEB-INF/ext-web/docroot/html/js/jquery-1.2.6.min.js


Step 2: copy top_js.jspf from source and place that in your hook -  /jsp-hook/docroot/META-INF/custom_jsps/html/common/themes/ and add the the line

            <script src="/html/js/jquery-1.2.6.min.js"></script>

at the end of top_js.jspf.

so now jQuery available throughout the portal in all the themes.