Recent Bloggers

Ankit Prajapati
Posts: 5
Stars: 0
Date: 9/18/17
Chirag Patel
Posts: 4
Stars: 0
Date: 9/15/17
Rahul Joshi
Posts: 5
Stars: 0
Date: 9/15/17
Jiten Vaghela
Posts: 1
Stars: 0
Date: 8/23/17
Kuldeep Acharya
Posts: 1
Stars: 0
Date: 8/16/17
Saurang Suthar
Posts: 5
Stars: 0
Date: 7/5/17
Jyoti Verma
Posts: 3
Stars: 0
Date: 6/29/17
Pankti Patel
Posts: 1
Stars: 0
Date: 5/27/17
Chandrika Baraiya
Posts: 5
Stars: 0
Date: 5/27/17
Atith Patel
Posts: 5
Stars: 0
Date: 5/23/17
« Back

Liferay 7-DXP Service Wrapper Hook

Liferay has implemented portal services in a way that makes it independent from core portlet classes. Such architecture allows us to modify any Liferay functionality easily without worrying about modification of core portlet classes. We can achieve portal service customization with the help of Service Wrapper hook. Basically, Liferay generates wrapper classes for all services. For example, BlogsEntityLocalServiceWrapper class is created for BlogsEntityService which contains methods to add, update, delete Blogs entry. If we want to modify any of these services then we need to create custom class that extends BlogsEntityLocalServiceWrapper via Service Wrapper hook. Once we deploy such hook, Liferay portal container will use custom service class instead of original service wrapper class.

 

Prerequisite :

Basic knowledge of Liferay 7 Development and Liferay Hooks

 

Previously, in Liferay 6.1 and 6.2, we created Hook plugin with entry of service wrapper in liferay-hook.xml file. In Liferay 7, we need to create module project using “servicewrapper” template. Here “ServiceWrapper.class” is used as service in Component class(which will be generated if you are using IDE).

 

Suppose you need to create service wrapper hook for Blogs entry. You need to create hook by following steps.

 

  1. Create gradle module project (I am using Eclipse with Liferay IDE plugin) with appropriate name. Select “servicewrapper” in Project Template name.

 

blog1.png

 

  1. Now select service for Blogs entry as shown in below screenshot and click on finish. IDE will create component class as per given class and package name.

 

LR 7/DXP Service Wrapper Hook

 

  1. Override addEntry method of BlogsEntryServiceWrapper class and prepend “Surekhatech” in blog title. Below is sample code for component class.

 

package com.st.hook;


import statements;


@Component(

immediate = true,

property = {

},

service = ServiceWrapper.class

)


public class CustomBlogsEntryServiceWrapper extends BlogsEntryLocalServiceWrapper {


public CustomBlogsEntryServiceWrapper() {

super(null);

}

 

@Override

public BlogsEntry addEntry(long userId, String title, String subtitle,

String description, String content, int displayDateMonth,

int displayDateDay, int displayDateYear, int displayDateHour,

int displayDateMinute, boolean allowPingbacks,

boolean allowTrackbacks, String[] trackbacks,

String coverImageCaption, ImageSelector coverImageImageSelector,

ImageSelector smallImageImageSelector, ServiceContext serviceContext)

throws PortalException {

 

title = title + " : Surekhatech";

 

return super.addEntry(userId, title, subtitle, description, content,

displayDateMonth, displayDateDay, displayDateYear, displayDateHour,

displayDateMinute, allowPingbacks, allowTrackbacks, trackbacks,

coverImageCaption, coverImageImageSelector, smallImageImageSelector,

serviceContext);

}

}


 

Hook is ready, deploy it in Liferay 7 server. Create any blog entry and you will see that “Surekhatech” is appended in blog title.

 

I have attached sample jar file which you can download.

 

Attachment : Service Wrapper Hook

Comments
No comments yet. Be the first.

Contact Us

Loading

Get in touch

Headquarter :
302, Landmark,
Nr. Titanium City Center,
Prahlad Nagar Road,
Ahmedabad, India - 380015.