Saturday, June 4, 2022

Make You Liferay DXP Application Configurable

 

Before Liferay DXP if we need to provide some configuration then we have two option :-

1)Provide configuration in portal-ext.properties

2)Use portal.properties 

In both cases we need to either redeploy the portlet or restart the server. In this blog we will see how to make our application configurable so that we don't need to restart or redeploy the portlet.Here i am using Liferay 7.3

So lets start this step by step :-


Step 1:- Create a simple MVC Portlet
Let's create a simple MVC portlet and then create a simple package in it. After that create a interface with this code :-

DemoConfiguration.java


Explanation:-

1)In the 9th line we provide the category where our configuration is displayed in control panel system setting.
2)In 10th line we need to pass 3 things 
   a)id : full path of your interface
   b)localization : your Language.properties file
   c)name : name which is displayed in system setting.
3)Here we can use keys those values we can pick from Language.properties or you can directly pass the value also. Like For sender and receiver description we pick from Language.properties and for gender description we directly mention.

Step 2:- Provide values in Language.properties
Now add the keys values which we use in DemoConfiguration.java

Language.properties

Step 3:- Deploy and Configure
Now deploy you portlet and go to control panel-> Configuration-> System Setting


Click on System setting then scroll down and you will see your category which we mention in DemoConfiguration.java



Click on category.LiferayIsEasy you will see your Demo Configuration inside System Scope



Here you can provide any values and click update.

Step 4:- Fetch values in Portlet
Now Open your portlet in my case DemoPortlet.java and paste this code :

DemoPortlet.java

Explanation:-

1)Focus on line 37 Where we pass configurationPid which is path of our interface
2)From 40 to 46 we initialize our configuration  .
3)From 51 to 53 we simply get the values.

Project Structure



Note : You can download the source code from here .

No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!