Wednesday, November 30, 2011

How to access custom portlet services in velocity template

By default we will have following property which won't allow us to use serviceLocator variable in velocity templates.

    # Input a comma delimited list of variables which are restricted from the
    # context in Velocity based Journal templates.

In order to access you need to change that property as below


Default findServce(serviceName)  method (what we normally use) searches @ portal level where as other one with extra parameter as shown here  findService(servletContextName, serviceName) searches @ particular portlet level

TO add more to it here are the method signatures & implementations in

        public Object findService(String serviceName) {
                Object bean = null;

                try {
                        bean = PortalBeanLocatorUtil.locate(_getServiceName(serviceName));
                catch (Exception e) {
                        _log.error(e, e);

                return bean;

        public Object findService(String servletContextName, String serviceName) {
                Object bean = null;

                try {
                        bean = PortletBeanLocatorUtil.locate(
                                servletContextName, _getServiceName(serviceName));
                catch (Exception e) {
                        _log.error(e, e);

                return bean;

HoW tO uSe

Suppose i have an custom Entity named MyEntity(defined through service.xml)

#set ($myEntityService = $serviceLocator.findService("", "com.rnd.common.portlet.service.MyEntityLocalService"))

I have a column named count under MyEntity, i can access as below

#set ($count =$myEntityService.getCount())


Hope that helps :)

Please feel free to add your comments. Cheers

Tuesday, November 29, 2011

How to open HSQL DB tables of Liferay in eclipse

Earlier i blogged about how to connect to HSQL DB from command prompt using HSQL Database Manager. Now as per request i have blogged to connect to HSQL DB form Eclipse

> Open Data source explorer in Eclipse

> Right click on Database Connections > New, you see screen looking like below as shown in Figure.1

> Type hsql as showing screen below & select HSQLDB - Give a name to your DB connection


> Do as described in Figure.2 below(Point to a Liferay DB which is using HSQL)

> You will see screen like below in Figure.3, once done close this window

NOTE : Here jar file you will using should point to the hsql.jar you have for Liferay installation under tomcat/lib/ext (Below is the screen shot for the same)

> Now you have to give proper Liferay DB name & Database location - Give DB connection other will be populated automatically. Check the save password check box. In my case DB location is


You change this path according to your Liferay instance DB running on HSQL

> You can test the connection as show below

 > Click on Next from above screen, you see below screen check for connection profile & click finish

> You will be redirect to Datasource Explorer, which looks like below

Please feel free to add comments.

Cheers :)

How to open HSQL DB tables of Liferay

Some times we may need come across vague where we have to check few things immediately. Need to make some new version of Liferay up & running quickly, have to check DB for reference

As we all know default DB that Liferay uses in HSQL DB.

Here are the quick steps to how to open HSQL DB table entries in Liferay

Step 1: Download HQSLDB from Extract into some folder (eg. D:\hsqldb)

Step 2: You can use the HSQLDB DatabaseManager to view this database. Run the following from the command line to invoke the tool.

    java -cp D:\hsqldb\lib\hsqldb.jar org.hsqldb.util.DatabaseManager

    In the "Connect" dialog, select the following options:
    Type: HSQL Database Engine Server
    Driver: org.hsqldb.jdbcDriver
    URL: jdbc:hsqldb: (In my case i have my Liferay installation @ D:\projects\liferay\lr523\liferay-portal-5.2.3\data\hsql so i have to give path as jdbc:hsqldb:D:/projects/liferay/lr523/liferay-portal-5.2.3/data/hsql/lportal for URL)
    User: sa

Please see the attached image for reference of settings we need to provide

That's it now you should be able to see all the tables. Database interface may not be quite intuitive as other commercial/open-source DB interfaces. Please check the below image for ref

UPDATE : Check the blog for how to connect to HSQL DB using Eclipse

Please feel free to provide feedback if any

Cheers :)

Thursday, November 24, 2011