Override OSGi Component Properties

Override OSGi Component Properties

Overview

You may need to change some properties for Liferay's OSGi @Component in order to customize the built-in behavior, but you don't want to override the whole component. Fortunately, there is an easy way to achieve this. This article will explain how to do this.

Sample scenario

Let's say, you want to add the "Notifications" portlet to a user profile page. But when you try do this - you can't find this portlet among the available ones:


When you check the sources - you'll find out, that "Notifications" portlet is hidden:


Obviously, you just need to change the display category. But this is the internal Lifeay code, which you can't just modify.
Fortunately, all those properties are easy customizable.
Here are the required steps:
  • Create a [Component-Classname].config class in [Liferay]/osgi/configs folder;
  • Add properties you need to override inside the created file;
  • Restart Liferay to make the changes applied.
In our scenario we need to create a file com.liferay.notifications.web.internal.portlet.NotificationsPortlet.config in [Liferay]/osgi/configs with content:
com.liferay.portlet.display-category="category.social"
(to display "Notifications" portlet under "Social" category).
Restart Liferay, and you'll see the portlet among available ones:


In a similar way you may modify any properties for any components in Liferay. 
This mechanism gives flexible and powerful way for OSGi components customization.

Comments

Popular posts from this blog

Liferay Search Container Example

Liferay DXP - max upload file size

Liferay Keycloak integration