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.

Step-1:-

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.

Step-2:-

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.

@Component(

                immediate = true,

                property = {

        "javax.portlet.name= com_liferay_login_web_portlet_LoginPortlet"

    },

    service = PortletFilter.class

)

public class MyLoginPortletFilter implements RenderFilter {

 

                @Override

                public void destroy() {

                }

 

                @Override

                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");

                }

 

                @Override

                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.

VIEW-------------1(001)

UPDATE-----------2(010)

DELETE----------4(100)

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

     HAS PERMISSION;

}ELSE{

    DON’T HAS PERMISSION

}

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">
    <settings>
        <setting configurable=”true” key="header-type" value="HEADER_TYPE_1" type=”Text”/>
    </settings>
</theme>

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

#set($articleID=$theme.getSetting(“header-type”))
$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.

SUMMARY

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{
 
 @Override
 public void processAction(ActionRequest actionRequest,
 ActionResponse actionResponse)
 throws IOException, PortletException {
 
    try {
       
        PortletActionInvoker.processAction(
         "com.liferay.portlet.documentlibrary.action.EditFolderAction",                               getPortletConfig(),
          actionRequest, actionResponse);
 
     }
     catch(Exception e) {
 
        e.printStackTrace();
     }
}
 
}

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 = [
           {"name":"California"},
           {"name":"Colorado"},
           {"name":"Connecticut"},
           {"name":"Colorado"}
           ]; 
   new A.AutoCompleteList(
       {
        allowBrowserAutocomplete: 'false',
        activateFirstItem: 'true',
        inputNode: '#<portlet:namespace/>states',
        resultTextLocator: 'name',
        resultHighlighter:'phraseMatch',
        resultFilters: ['startsWith'],
        minQueryLength: 2,
        maxResults: 10,
        queryDelimiter : ',',
        render: 'true',
        source:states
   });  
</aui:script>
 

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 9 results.
Items 20
of 1