We used cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it. What For?

« Back to Blogs

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.




  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;


immediate = true,

property = {


service = ServiceWrapper.class


public class CustomBlogsEntryServiceWrapper extends BlogsEntryLocalServiceWrapper {

public CustomBlogsEntryServiceWrapper() {





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,





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

contact-us Request a callback WhatsApp