Liferay.com

Saturday, November 16, 2013

Some useful notes :)

p_p_lifecycle

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

http://alloyui.com/api/ - This points to latest documentation always (which is 2.0.x)

http://alloyui.com/versions/1.0.x/api/

http://alloyui.com/versions/1.5.x/api/

How to navigate to different versions from http://alloyui.com/, 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 = A.one('#openServeyWindow').getAttribute('href');
var jsAtt = sessionId;
A.one('#openServeyWindow').setAttribute('href', hrefDefaultVal+jsAtt);

A.one('#openServeyWindow').setAttribute('onclick', "saveEntry('${count}','${newSessionIdPK}','${recentSessionIdPK}','"+buttonClicked+"' );");

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

closeRmiWindow();
window.location.replace('${lastAccessedPageUrl}'); // to redirect to previous page
},
['node-event-simulate']
);

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 XXXLocalServiceImpl.java/XXXServiceImpl.java 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

http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Fast+Development+of+Liferay+Plugins+with+Tomcat

Njoy fast dev..ing

Saturday, May 18, 2013

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

UseCase

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: portal.properties file of your portlet should have below entries

# to run insert statements
release.info.build.number=110
release.info.previous.build.number=100
upgrade.processes=com.aon.org.admin.upgrade.UpgradeProcess_1_1_0


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



Step 3:

package com.test.org.admin.upgrade;

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 portal.properties


application.startup.events=com.aon.org.admin.util.OrgStaticDataStartUpAction

Step 3:


package com.test.org.admin.util;

import com.test.org.management.service.OrgTypeLocalServiceUtil;
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.events.SimpleAction;
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 {

@Override
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()) ){
continue;
}else{
recordsExists = false;
}
}

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

LOGGER.warn(e);
}
}

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

}

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