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 = {

        "javax.portlet.name= 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 6 results.
Items 20
of 1