Liferay provides lots of configurations under Instance settings for OOTB features. We can add our own configuration in the Liferay control panel so that we can save configurable values for our project. Here you will learn about how we can implement custom configuration in Liferay 7.2.

Prerequisites

  • Java
  • Liferay portal 7/7.x

Environment Requirement

  • JDK
  • Eclipse
  • MySQL

1) Create module project with below classes

How to create custom configuration under Instance Settings in Liferay 7.2

2) Create a Java interface

Its interface is used to configure the Liferay form application.

 

Meta.OCD

Registers this class as a configuration with a specific id. The ID must be the fully qualified configuration class name.

Meta.AD

Specifies optional metadata about the field, such as whether it’s a required field or if it has a default value. Note that if you set a field as required and don’t specify a default value, the system administrator must specify a value in order for your application to work properly. Use the default property to specify a default value.

3) Create category and section

If you don’t want the default sections and categories, you can make your own by implementing the ConfigurationCategory interface.

Note :- please edit the Language.properties located in module project’s location /src/main/resources/content/Language.properties

4) Create a configuration bean declaration

It’s used to register your configuration class.

After registering with a ConfigurationBeanDeclaration, you’re ready to use your Configuration in module projects.

Deploy the configuration module and now you can see your configuration in your Control Panel Configuration Instance Settings.

How to create custom configuration under Instance Settings in Liferay 7.2
How to create custom configuration under Instance Settings in Liferay 7.2
Now you can fetch custom configuration values in your custom portlet using the following code.

This will print the color configuration value you have saved from Liferay Control Panel.