Liferay 7 theme development using IDE-2

General Blogs December 19, 2017 By Sushil Patidar

I wrote blog for theme development with IDE . Further I explored the way to configure gradle project. I would like to share those steps that I have experienced hard to find and many developers I saw asking for the same thing on the forums.

Gradle Configuration


By default, if we create theme using IDE it templates are built using freemarker and parent theme is “_styled”. I was also stuck to this scenario and explored to find a way we can configure these particular options .

As we saw in previous blog, if we create module theme project using Gradle, in the build.gradle it applies theme builder plugin. This plugin add buildTheme gradle task to the project which generate theme files based on the parentTheme and templateExtention property configured in the task.  By default, following are the values for these property.








To change the values of these properties in the case if we want to generate theme files using unstyled theme and velocity template it need to configure the task properties as follows build.gradle file.



Now run buildTheme task,  files will be generated as per above configuration.



One need to include the gradle dependency based on type of parent theme configured like follows.



Liferay DXP OSGI module project dependency resolution

Technical Blogs October 4, 2017 By Sushil Patidar

OSGI Module Gradle Project

We have worked on ANT and MAVEN with Liferay in previous versions. In Liferay DXP Gradle has been introduced. It is quite an interesting feature to learn with Liferay development.

Gradle is powerful and wonderful tool, but due to lack of documentation to use with Liferay I sometimes stuck with dependencies resolutions. I explored it further to overcome the dependency resolution blues that often came to my way. I went through many blogs, forums and wikis and came to know some interesting points which I wanted to sum up on one place that might be helpful for the community.

Generally to add dependency in the build.gradle dependencies we do as follows

dependencies {



      compileOnly 'com.fasterxml.jackson.core:jackson-databind:'


In the above declaration what it “compileOnly” task do is , it compile the source code,it doesn’t include the this dependency and it’s transitive dependencies in the jar package that creates problem while deploying the module in the OSGI container as dependency jars are not resolved.

To overcome this scenario we need to include all transitive dependencies in the dependencies declaration. But how do we know what is the dependency tree?

To get the transitive dependencies and their version, there is task which helps a lot at this step. For that go to Liferay module project ,open CMD and execute below task.

gradlew dependencies --configuration compileOnly

This task  prints the dependencies tree as  below.

compileOnly - Compile dependencies for source set 'main'.



\--- com.fasterxml.jackson.core:jackson-databind:

     +--- com.fasterxml.jackson.core:jackson-annotations:2.6.0

     \--- com.fasterxml.jackson.core:jackson-core:2.6.7


It gives us the idea that jackson-databind- depends on jackson-annotations-2.6.0  and jackson-core:2.6.7 those are also need to include in the build.gradle . To instruct build to include these dependencies in the jar package. We need to configure bnd.bnd as follows. Though David has well explained in his blog for below bnd.bnd entries, i want to recall few of them to understand the context properly.


      lib/jackson-annotations.jar=jackson-annotations-2.6.0.jar, \



Above instructs build to include dependency jars in the module jar package. But to configure OSGI bundle classpath, it should be included as follows.

Bundle-ClassPath: \






Above are steps that gives us more control to specify transitive dependencies and their version. But if we want to rely on gradle to fetch transitive dependencies and configure MENIFEST.MF then compileInclude type can be used in the build.gradle as follows.

dependencies {



      compileInclude 'com.fasterxml.jackson.core:jackson-databind:'


In this case if build gradle plugin it not only compile the source code but also include dependency mentioned and it’s transitive dependency in the module jar package.

To get the transitive dependencies and their version included by gradle, go to Liferay module project ,open CMD and execute below task.

gradlew dependencies --configuration compileInclude

It will print the dependency tree of the dependencies that gradle have included in the jar package. In this case we don’t need to configure bnd.bnd, it is done by gradle task in the MENIFEST.MF in module jar.

OSGI Module Maven Project

For a osgi module project created through Liferay IDE as well dependency analysis is little bit same as Gradle project we have seen above.

Assume we have added a dependency in the Module project.











To get the dependency tree ,execute following goal.

mvn dependency:tree

It will print the dependency tree like below which help us what all transitive dependency of the project  that we have declared in the project pom.

\- com.fasterxml.jackson.core:jackson-databind:jar:

    +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.0:compile

    \- com.fasterxml.jackson.core:jackson-core:jar:2.6.7:compile

It gives us the idea that jackson-databind- depends on jackson-annotations-2.6.0  and jackson-core:2.6.7 those are also need to mention  in the bnd.bnd file similar to as we did for gradle project above .i.e.


      lib/jackson-annotations.jar=jackson-annotations-2.6.0.jar, \




Bundle-ClassPath: \







As osgi resolve dependencies in deifferent way based on the entries in MENIFEST.MF so above is another step we need to take care from OSGI point view other than build tools Gradle and Maven dependency resolution. Hope it helps.


Adding Portlet URL in the Portlet Toolbar in Liferay 7

General Blogs March 7, 2017 By Sushil Patidar

Portlet URL can be added using Portlet Tool Bar Contributor module. Here also osgi plays its magic of modularity. It can be implemented through OSGI service component. Service component can be either in same module or different one. Wiki page elaborate it through blade tool. Below are steps to implement it  through eclipse IDE. 


Create Module Project and select Template as shown below.


It will auto generate Portlet Tool Bar Component class. In the component class one thing is necessary the portlet id on which you want to add toolbar.Now Override the method as shown below to add URL in Menu Item that will be redirected once user click the URL.



Deploy the module, you can see the Icon defined above on the portlet Header.

Multiple URL Menu Item Can be added following the same approach. Permission check can be done by getting the reference of permission checker in the service component.  Permission check will ensure whether to show URL to a User based on granted permissions.

Overriding Module JSP in Liferay 7 using Liferay IDE

General Blogs December 28, 2016 By Sushil Patidar

With the release of Liferay IDE 3.1 M1 ,I noticed one more interesting feature that developers might be looking for, is that jsp of the OOTB module JSPs  can be modified using Liferay Module Fragment project in Liferay IDE 3.1 M1. One approach to override module JSPs is mentioned on page.

As described below , JSPs fragment can also be generated using Liferay IDE 3.1 M1.

Create new module fragment project.


Configure Liferay Runtime environment and select it as shown below.

As next step, now select the Host OSGI bundle.

After selecting the Host OSGI bundle, need to select the jsp  you want to override in the selected module.

So after selecting Host OSGI bundle and file that need to override, it is almost done. Click finish to proceed further, it will create Module Fragment Project structure. In the generated project structure , if we see file blog-fragment/bnd.bnd .

Following two entries are important to add that is mentioned on the page.

Fragment-Host: com.liferay.blogs.web;bundle-version="2.0.0"

In the generated module fragment project , selected jsp is also added that can be modiefied.



Now Build the above created module fragment project using the build Gradle task. 

It will generate the packaged JAR in blog-fragment/build/lib folder. Deploy the generated JAR to see the changes.

Liferay 7 theme development with IDE

General Blogs December 28, 2016 By Sushil Patidar

Liferay IDE 3.1 M1 has been released. Previously i explored Liferay 7 theme development using theme generator as expalined on page. Since than I was curious to do it through Liferay IDE that seems to more convenient for developers. In Liferay IDE 3.1 M1, I have noticed that theme project templates are added. Explaining steps so that it might be helpful for the community.

Follow the below steps to create themes in Liferay 7 using IDE 3.1 M1.


Go to Liferay workspace and create Liferay Module Project as shown in below. Select Project Template for theme. 

After creating theme module project. Project structure is created to develop custom theme.

At this point if you look at the project structure, there is no build folder generated.


Now build theme using following Gradle Task. 

It will generate theme files in the build folder as shown below.

This files are generated from classic styled theme, if you want to override files just place them in the first-theme/src/main/webapp folder.

Like if you want to override portal_normal.ftl, create folder templates in first-theme/src/main/webapp/ as follows and place portal_normal.ftl.


Step-3:- Build theme using following gradle task.


It will package theme in war in the  first-theme/build/libs folder. Deploy this WAR file to see the custom changes. 


Portlet Filters in Liferay 7

General Blogs October 4, 2016 By Sushil Patidar

Liferay 7 comes with a lot of feature and each feature is worth to learn.  Portlet Filter is one of them. However, it is possible to write portlet filter in earlier versions but in Liferay 7 it has certain benefits.

As compared to earlier version Portlet Filter can be deployed as service in OSGI. There is no need to write filter in the same portlet plugin that is the ultimate benefit of Liferay 7 modular architecture, it gives us the possibility to apply filter on OOTB portlets with ease. This is beneficial where It can be applied and removed independently from the portlet without redeploying the portlet as the contracts between osgi services are loosely coupled.


In earlier version It is hard to apply filters on OOTB portlets. I think, it is not possible without EXT plugin. Taking advantage of OSGI in Liferay 7, Portlet Filter on OOTB portlet can be applied as a service and can be removed without need of the Portal downtime.


There can be following Portlet Filters.

a) Render Filter: -Render Filter mainly implements the doFilter(RenderRequest request, RenderResponse response, FilterChain chain) method of the the javax.portlet.filter.RenderFilter class.

b) Resource Filter: - Resource Filter implements the doFilter(ResourceRequest request, ResourceResponse response, FilterChain chain) method of the the javax.portlet.filter.ResourceFilter class.

c) Action Filter: - Action Filter mainly implements the doFilter(ActionRequest request, ActionResponse response, FilterChain chain) method of the the javax.portlet.filter.ActionFilter class.

d) Event Filter: - Event Filter mainly implements the doFilter(EventRequest request, EventResponse response, FilterChain chain) method of the the javax.portlet.filter.EventFilter class.


To define PortletFilter first step there is need to declare following properties that will identify this service as PortletFilter and on which portlet service it is applied. Suppose we want to apply filter on Login Portlet. It can be done just by writing an independent module that has following component class.


                immediate = true,

                property = {

        " com_liferay_login_web_portlet_LoginPortlet"


    service = PortletFilter.class


public class MyLoginPortletFilter implements RenderFilter {



                public void destroy() {




                public void doFilter(

                                                RenderRequest request, RenderResponse response, FilterChain chain)

                                throws IOException, PortletException {


                                System.out.println("Before filter action");

                                chain.doFilter(request, response);

                                System.out.println("After filter action");




                public void init(FilterConfig filterConfig) throws PortletException {




Liferay Role Association with Users and Permissions Algoritm 6

General Blogs June 5, 2016 By Sushil Patidar

Role is basically a set of permissions. When a Role is assigned to a User, he is capable to do whatever permitted to that Role. Liferay provide well defined roles and permissions architecture that can be managed from control panel. Through this blog I wanted to describe how user are associated to roles directly or indirectly through Site, Organization and User Groups.

1)Regular Role-Regular role is created to define permissions within the portal scope. User can be associated to Regular Role either directly or if he is member of a site, organization, User Group as follows.

2)Site Role- Site  role is created to define permissions within the site scope. Site Role is assigned to site. If user is member of site either directly or indirectly if he is member of organization or User Group which are further member of that site, he has the permissions of Site Role.

3) Organizational Role- Organizational role is created to define permissions within the organization scope. Organizational Role can be assigned to organization users. If a user is member of organization, he can be assigned to organizational Role.

Permissions Algorithm-Permissions are actions that a user is authorized to do. As permissions is the core part of Liferay Architecture. For each entity, it requires a lot entries to be added in database. In Liferay 6.X Advanced Permissions Algorithm 6 is introduced that reduces the database size significantly.

There are following table in which permission entries are added.

1)ResourceAction- In Liferay we can define action for following resources.

    a) PortletResource

     b) Entity Resource

Resource actions might be like VIEW,UPDATE, DELETE. For each resource action a entry is added in the ResourceAction table. Each resource action is assigned a bitwise value. Let assume following are the values.




2)ResourcePermissions-This table contains the permissions that are assigned to a Role in a particular scope. Permissions are grouped together using bitwise OR and added as single entry.

Permissions->VIEW(001) OR UPDATE(010) OR DELETE(100)=111

So if a role as above three permissions then bitwise OR comes as a single value i.e . 111.It reduces the size of database significantly by eliminating multiple entries.

When it is needed to check that a particular Role has particular permission, algorithm 6 checks it by following rule.

IF((Role Permissions)AND( Action)==(Action)){





3)ResourceBlockPermissions-In Resource Block permissions , similar set of permissions are considered as block so as to reduce duplication. To understand this concept you can go through the blog in which resource block permission are explained very much in detail.

Power Of WCM with Theme Development

General Blogs June 2, 2016 By Sushil Patidar

Liferay provide advanced web content system that empower business users to configure and create Web Content. On other hand Liferay Theme plugin provide Configurable theme settings. This flexibility of web content management system used with theme can leverage additional power for Liferay Portal projects.

In theme there are sections like navigation, header and footer need regular changes like changing content and text of these sections. And on each change it requires development and deployment efforts. As we know Liferay Web Content Management system allows users to modify contents on the go. If we think Theme sections (Header, Footer and Navigation) as a web content. As localized web contents can be created, Business users can change localization Text anytime they want for links and text rather than adding them language properties and series of deployments through various environments. Also images used in Header Footer can be changed any time through Web Content without involvement of development Team.

By embedding web content in theme, these features can be achieved easily.

$journalContentUtil.getContent( $themeDisplay.getCompanyGroupId(), $webContentID, “”, $locale.toString(), $themeDisplay )

In the above code snippet $webContentID can be hardcoded as “HEADER. Now create web content “HEADER” using structure/template.

Sometimes there are situations when there is requirement that Business users want variety of Header, Footer and Navigation. In such situations Configurable Theme settings can be used for advanced control.

Liferay Provide configurable theme settings through which we can add some fields Text, Dropdown, and Radio. As an example take a case that user wants two Header Type and want to make it configurable

Step-1:-In this case create two web content (HEADER_TYPE_1 and HEDAER_TYPE_2) .

Step-2:-Add configurable setting in theme as follows.

<theme id="theme_id" name="Theme-Name">
        <setting configurable=”true” key="header-type" value="HEADER_TYPE_1" type=”Text”/>

 Step-3:-And embed the web content in theme using the theme-setting value as follows.

$journalContentUtil.getContent( $themeDisplay.getCompanyGroupId(),$articleID ,””, $locale.toString(), $themeDisplay)

Step-4:- When required you can change theme setting from HEADER_TYPE_1 to HEADER_TYPE_2 as shown below by navigating to theme settings.


With use of configurable theme settings provide the benefit of selecting choice of different Section (Header, Footer, Navigation) Content for different pages by using single theme plugin as well as ease of modifying the content whenever required from the control panel using the web content management.

Calling OOTB portlet struts actions

General Blogs June 7, 2014 By Sushil Patidar

Many a time it is required to call OOTB portlet struts action from custom portlets.This can be done using the simple approach as follows.


public class TestPortlet extends MVCPortlet{
 public void processAction(ActionRequest actionRequest,
 ActionResponse actionResponse)
 throws IOException, PortletException {
    try {
         "com.liferay.portlet.documentlibrary.action.EditFolderAction",                               getPortletConfig(),
          actionRequest, actionResponse);
     catch(Exception e) {

Comma separated multiple Autocomplete in one field

General Blogs June 4, 2014 By Sushil Patidar

As there are lot more improvements in the Alloy UI 2.X . Some attributes have been removed and some are replaced for auto complete. So to implement the comma separeted multiple autocomplete in one field in Alloy UI 1.5 there was attribute delimChar: ','   that have been replaced with queryDelimiter : ','   

In Liferay 6.2 this functionality can be achieved by using the following AUI script.



<aui:input name="states" type="textarea" ></aui:input>


<aui:script use="autocomplete-list,aui-base,autocomplete-filters,autocomplete-highlighters">
   var states = [
   new A.AutoCompleteList(
        allowBrowserAutocomplete: 'false',
        activateFirstItem: 'true',
        inputNode: '#<portlet:namespace/>states',
        resultTextLocator: 'name',
        resultFilters: ['startsWith'],
        minQueryLength: 2,
        maxResults: 10,
        queryDelimiter : ',',
        render: 'true',

Searching entities through custom attribute value.

General Blogs April 5, 2014 By Sushil Patidar

If you need to search Users who has particular custom attribute value .Using liferay expando API ,this can be acheived easly as follows.

String attrValue ="IT";
String attributeName ="user-department-name";
String tableName = ExpandoTableConstants.DEFAULT_TABLE_NAME;
long classNameId =ClassNameLocalServiceUtil.getClassNameId(User.class);
List<ExpandoValue> expandoValues =ExpandoValueLocalServiceUtil.getColumnValues(companyId, classNameId, tableName, attributeName, attrValue, -1,-1);
for(ExpandoValue expandoValue:expandoValues)
  try {
      long userId = expandoValue.getClassPK();
      User user  =UserLocalServiceUtil.getUser(userId);
  catch(NoSuchUserException nsue) {
   _log.error("No Such User Exist");


Showing 11 results.
Items 20
of 1