Saturday, November 16, 2013

Some useful notes :)


p_p_lifecycle=0 > render url

p_p_lifecycle=1 > action url

p_p_lifecycle=2 > serveresource url

you might be have seen p_p_lifecycle in query string many times BUT might be not knowing exactly what is each value exactly mean

It is important to know what are the possible values for p_plifecycle & how they can be helpful, might be useful in forming friendly urls (of Freindly url routes feature of Liferay)

Liferay Sample plugins

For latest version of Liferay released you will have at

You will have plugins for other versions tagged appropriately here

Tuesday, November 12, 2013

Browsing through different Alloy UI versions documentation

As of writing this post we have 1.0.x, 15.x & 2.0.x Alloy UI versions available

For API documentation related to exach version you can browse as below - This points to latest documentation always (which is 2.0.x)

How to navigate to different versions from, you will some selectable kind of option at ALLOYUI as show below

Hope it helps some people who have hard time finding out AUI documentation

Using Liferay.provide - to add global java script function

An example function

Liferay.provide(window, 'existingUser', function(sessionId, buttonClicked) {
var A = AUI();

var hrefDefaultVal ='#openServeyWindow').getAttribute('href');
var jsAtt = sessionId;'#openServeyWindow').setAttribute('href', hrefDefaultVal+jsAtt);'#openServeyWindow').setAttribute('onclick', "saveEntry('${count}','${newSessionIdPK}','${recentSessionIdPK}','"+buttonClicked+"' );");

if (navigator.appName == 'Microsoft Internet Explorer') {// as AUI simulate is not working in IE, handling through
var elem = document.getElementById("openServeyWindow");
if (typeof elem.onclick == "function") {
}else{ // other browsers
// click working fine with below command for IE, redirect is not happening'#openServeyWindow').simulate('click');

window.location.replace('${lastAccessedPageUrl}'); // to redirect to previous page

Somehow this works well compared to (it seems because of lazy loading aui does with aui:script use attribute)
// whole function code from above

Wednesday, October 9, 2013

Fast Plugin Development (tomcat)

This is really useful when working on plugin development & making frequent changes to jsps/java files.

If you have Service builder as part of your plugin & you changed any of file(s) - after you re-run service builder, you may need to re-deploy/restart the server. Service builder re-run seems messes up context (with auto-reload)

I did used this setup long back though (5.2 EE sp3) BUT found this is very helpful

Njoy fast

Saturday, May 18, 2013

Direct SQL insert statements to Liferay out-of-the-box tables


I came across a scenario where i need to insert some values into default liferay table on my custom portlet deployment. Particularly ListType table..

FYI, I am using Liferay 6.1 EE GA2

Two approaches came into my mind

1. Using Hook's upgrade process approach

Step 1: file of your portlet should have below entries

# to run insert statements

Step 2: liferay-hook.xml should have below entry

Step 3:


import com.liferay.portal.kernel.upgrade.UpgradeProcess;

public class UpgradeProcess_1_1_0 extends UpgradeProcess {

public int getThreshold() { return 110; }

protected void doUpgrade() throws Exception {
// your upgrade code here. } }

runSQL("insert into ListType (listTypeId, name, type_) values (22000, 'local-client-address', 'com.liferay.portal.model.Organization.address')");
runSQL("insert into ListType (listTypeId, name, type_) values (22001, 'global-client-address', 'com.liferay.portal.model.Organization.address')");

That's it, you are good to go, it will insert relevant data into respective ListType table.

2. Using SqlUpdateFactoryUtil Liferay API method to insert according to my needs in my Entity (I have service layer if you don't have one you can create a facade i.e., entity without columns)

Step 1: For e.g., if your entity name is Dummy, in DummyLocalServiceUtil add below method

        public void insertStaticData(){

insert into ListType (listTypeId, name, type_) values (22000, 'local-client-address', 'com.liferay.portal.model.Organization.address');
insert into ListType (listTypeId, name, type_) values (22001, 'global-client-address', 'com.liferay.portal.model.Organization.address');
// DataSource dataSource = (DataSource) PortalBeanLocatorUtil.locate("liferayDataSource");
String insertQuery = "insert into ListType (listTypeId, name, type_) values (22002, 'local-client-address', 'com.liferay.portal.model.Organization.address')";

SqlUpdate _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(orgTypePersistence.getDataSource(), insertQuery, new int[]{});

int count = _sqlUpdate.update();
System.out.println("after update : no of records update : count length : "+ count);

Step 2: add an application startup events using hook, add below entry to

Step 3:


import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.model.ListType;
import com.liferay.portal.service.ListTypeServiceUtil;

import java.util.List;

public class OrgStaticDataStartUpAction extends SimpleAction {

public void run(String[] ids) throws ActionException {
// get types
List types = null;

try {
types = ListTypeServiceUtil.getListTypes("com.liferay.portal.model.Organization.address");

boolean recordsExists = true;
for (ListType listType : types) { // need to check for our custom values local & global if not add
if(!"local-client-address2".equalsIgnoreCase(listType.getName()) && !"global-client-address".equalsIgnoreCase(listType.getName()) ){
recordsExists = false;

if(!recordsExists){"Record not exists: starting insert");
OrgTypeLocalServiceUtil.insertStaticData();"Record not exists: end insert");
catch (Exception e) {
//type = new ListTypeImpl();


private static final Log LOGGER = LogFactoryUtil.getLog(OrgStaticDataStartUpAction.class);


Hope this will be helpful to some people. Blogging after long time - cheers :)