Sort Solr Search Result

Below snippet will help you to sort solr search results.

Few things i would like to highlight about solr result sorting.
You can not sort tokenized field i mean if you have defined your solr field with the type text or textToTight.
You can sort the field which have type string . You can create dynamic fields easily in solr.
Add below entry in schema.xml and solr will automatically create field with the type string.

<dynamicField name="*_sortable" type="string" indexed="true" multiValued="false" stored="true" />

If you use any field with suffix _sortable then solr will automatically create field if it is not exist.

Sort Search Container Result

To sort search container result follow below steps.

1) Create search container in your JSP.

2) Create search container in your controller and set result in search container object.

3) Get sorted results using dynamic query.

Connect Liferay with SAP using SAP JCO Connector

This post will elaborate you on how to connect your Liferay portal with SAP Database.
Many times we want need data from SAP database either using web service call or using any third party connector.
In this post we are going to use JCO connector to connect Liferay portal with SAP Database.


1) First download SAP JCO Connector for your operating system from
If you are using windows then make sure you download correct version of sapjco dll and jar.
For windows you need to place sapjco dll inside Windows\System32 directory

2) Next thing is configure sapjco3.jar inside Lifeary portal.
Place this jar inside [LIFERAY_TOMCAT]/lib/ext.

Liferay SAP Integration

Following diagram will give you some idea on integrating Liferay with SAP. [Image 1 Diagram]

SAP Java Connector (SAP JCo) is a middle ware component that supports communication with the SAP Server in both directions: inbound calls (Java calls ABAP) and outbound calls (ABAP calls Java).

In this post we will only try to understand inbound calls on how java calls ABAP (SAP)

There are basically 3 steps required to connect with this SAP System.

  1. Defining Destination
    • Define and prepare property file with all connection details.
    • Connection details includes
      1. Host Name
      2. System Number
      3. Client Details
      4. User Name
      5. Password
  1. Establishing Connection
    • In the 1 st step we created property file with all connection details.
    • In this step we are going to use property file to establish connection with SAP System.
  1. Executing Function
    • The RFCs enable you to call and execute predefined functions in a remote system.
    • The RFCs manage the communication process, parameter transfer, and error handling. 


  • I have created sample portlet in LR 6.1 GA2 to connect liferay with SAP database.
  • Portlet will display success message when connection is successfully done.
  • Download and play with this portlet. Here is the download link.
  • Following are some portlet screens that will help you to understand this sample portlet.

  • Click on Test SAP Connection button to connect with SAP System.
  • Once Connection is successfully done you will see following screen.

  • Define all connection related properties inside file of this sample portlet.

Reports Portlet - User Guide

I was just playing with Reports EE portlet available on Liferay market place. Thought to make user guide so that other can know how to use this portlet.

- Download this app from Market Place
- Place downloaded lpkg file in deploy folder.
- This application has one is for normal User and second is for admin.
- Once deployed admin can access this application from control panel.(Control Panel --> Reports Admin)
- To use this application configure data source first.
- Select Source tab and you will see below screen. Click on Add source button to add new database source.

- Fill required details to connect with database. To verify database connection click on Test Database Connection.
- Once database source is added next thing is to upload jrxml file (You need to crate reports template/jrxml using i Report)
- To test this app i have created one example report template which will basically display user from Liferay database.
- Download sample jrxml from here. Once downloaded change extension to jrxml)
- Select Definitions tab to add new definition (report template)
- Fill required details as shown in below screen shot. Make sure you select appropriate database from drop down.

- Upload jrxml file created using i Report.
- Next thing is to generate report based on this report template.
- Go to Definitions tab select definition and click on add report as shown in below screen shot.

- Select desired report format. You can also deliver this report via email .Click on Generate button to generate report.

- All the generated reports will be visible in Reports tab.

- Click on generated report and you will see following screen. Click on download link to view/save report.

Report with Parameter 

You can also add any parameter at the run time . In above example all the users will be placed in report but in case if you want to filter list based on user input then you can do this by adding parameter while adding definition.

Specify parameter while generating report see following screenshot for more detail.
You can download jrxml with parameter from here.

Schedule Report

You can also schedule report . Report will be generated and available for user at specified time and also it can deliver via email at the same time.

Plugin Portlet Migration Tips

If you are upgrading your LR plugin portlet from any LR version to any other version then you can use below steps / suggestion .

1) Create a new portlet in LR X.X using this command. ./create.bat portletName “PortletDisplayName”.

2) Copy and paste All the configuration file from old plugin portlet-->docroot>Web-INF

(ie. web.xml ,service.xml portlet.xml,liferay-portlet.xml,liferay-display.xml and file) to new plugin portlet.

Do required changes in every xml if required. i.e if you have make entry for dependecy jar into it may possible that name of old jars might have changes.
For example jstl.jar in Liferay 5.2SP3 is now changed to jstl-api.jar in Liferay 6.1 tomcat 7.0

3) Build services inside new plugin portlet.

4) Place your custom for services inside and again build services of your new portlet.

5) Copy all JSP , JS , Images and CSS from old plugin portlet into appropriate folder of new plugin portlet.

6) Copy all your custom Java code (Other then service files as we have already builded service in above steps for new plugin portlet) from your old plugin portlet to new plugin portlet.

7) Add required files in build path if its your first plugin portlet in a fresh bundle. Like util-java.jar , util-bridge.jar , portlet.jar and portlet-service.jar .Ignore this step if all this files already avilable in build-path.

8) Remove all existing imports from the java classes.

9) One by one include all required java classes.

10) If there is any changes in New APIs then do required changes.

11) Same way for JSPs . Remove all your existing imports and try by importing them again.

Change User Portrait from Custom Portlet in Liferay 6.1

Use below tag if you want to provide change and delete user portrait functionality from your custom portlet.

Encrypt URL Parameter in Liferay

Many time we need our URL parameters to be encoded when pass some sensitive information. So here the code which will help you to encode and decode URL Parameters.

Using below snippet you can encrypt your parameters.

Below code you can use to decry pt parameter.
String emailAddress = Encryptor.decrypt(getEncryptionKey(), emailAddress);

Save Portlet Preferences in Liferay 6.1

With Liferay 6.1 if you are using configuration mode and if you want to store form elements values in preferences then this post will definitely help you.

You can store form elements value in preferences with less efforts (as compare to version below Liferay 6.1).

You just need to follow few syntax to achieve this functionality. Lets go step by step.

Define your AUI element with below syntax

<aui:input name="preferences--showFeedTitle--" type="checkbox" value="<%= showFeedTitle %>" />

It should follow pattern like preferences--paramName-- .

And make sure you use below Configuration class in your liferay-portlet.xml


By using this way we dont need to write any code to store form element value into preferences . DefaultConfigurationAction class will detect form element with specified syntax and store the same in preference for you.

In case if you want to retrieve value from preference then directly use

// No need to use that syntax to get value  

You can also visit Liferay for same thing . Following is my community blog link. Unique way to save portlet preferences

Enable NTLM for other browser in Liferay 6.1

Integration of NTLM is supported with only Internet Explorer due to security issues.
To enable NTLM for other browsers, follow below instruction make necessary changes in

Below is OOB code

Before Authentication liferay will perform check whether NTLM is enabled or not and also checks whether current browser is IE only.
So in case if you try to access site with browser other then IE in that case you will see login screen and user will not be authenticated automatically.

So just to enable NTLM with other browser you have to override  isFilterEnabled() method.
Remove check for IE and the updated code will be like this .

About BrowserSnifferUtil
BrowserSnifferUtil is one of the good API which can help you to detect your current browser and operating system based on user agent.

Abvoe method will return string . If you current browser is Internet Explorer then this method will return ie .
If your current browser is FireFox then it will return firefox and for remaining browser it will return other.

BrowserSnifferUtil.isIe(httpRequest) will retuen true if your current browser is IE. There are other methods in this util to check for Mozila , chrome , safari etc.

You can also check your current operating system using this util.
like isWindows(httpRequest) method will check if current operating system is windows or not.

Add Resource Permission in LR 6.1

Using ResourcePermission we can easily provid permission on resources. Earlier in LR5.X we were using ResourceLocalServiceUtil for the same purpose.
Look into this post for more information on how to add resource permission in LR5.X

For LR 6.1