Whether it's simple text fields, checkboxes, dropdown menus, or more
intricate structures like repeatable fields or nested forms, the DDM
annotation offers unparalleled flexibility. This level of customization
enables the creation of configurations that seamlessly align with the
desired data model. Such tailored setups ensure that users can
efficiently and effectively capture and manage data, enhancing overall
productivity.
Furthermore, the dynamic nature of DDM means that configurations can evolve
alongside evolving business requirements. As new data elements or validation
rules are introduced, DDM makes it straightforward to adapt and enhance the
configuration forms without requiring extensive rework.
Here are the steps for creating a DDM form for Liferay Configuration:
1. Create a simple Configuration interface.
@ExtendedObjectClassDefinition(
category = "stockfish",
scope = ExtendedObjectClassDefinition.Scope.SYSTEM
)
@Meta.OCD(
id = "com.stockfish.configuration.CustomConfiguration",
localization = "content/Language", name = "custom-configuration"
)
public interface CustomConfiguration {
@Meta.AD(required = false)
public String date();
@Meta.AD(required = false)
public String select();
@Meta.AD(required = false)
public String[] text();
@Meta.AD(required = false)
public String richText();
}
2. Creating a DDM form for customizing the form of Liferay Configuration.
Create a configuration form interface that replicates your settings UI.
Utilize the @DDMFormField annotation for each field, ensuring
attributes like label, properties, type, etc. are defined to
represent the form's elements accurately.
public interface CustomConfigurationForm {
@DDMFormField(label = "%date", type = "date")
public String date();
@DDMFormField(
label = "%select", optionLabels = {"%foo", "%bar"},
optionValues = {"foo", "bar"}, type = "select"
)
public String select();
@DDMFormField(label = "%text")
public String[] text();
@DDMFormField(label = "%rich-text", type = "rich_text")
public String richText();
}
Once the field annotations are in place, you can utilize the
@DDMFormLayout annotation to customize the UI of your configuration
form.
@DDMForm
@DDMFormLayout(
paginationMode = com.liferay.dynamic.data.mapping.model.DDMFormLayout.SINGLE_PAGE_MODE,
value = {
@DDMFormLayoutPage(
{
@DDMFormLayoutRow(
{@DDMFormLayoutColumn(size = 6, value = "text")}
),
@DDMFormLayoutRow(
{@DDMFormLayoutColumn(size = 6, value = "select")}
),
@DDMFormLayoutRow(
{@DDMFormLayoutColumn(size = 12, value = "date")}
),
@DDMFormLayoutRow(
{@DDMFormLayoutColumn(size = 12, value = "richText")}
)
}
)
}
)
public interface CustomConfigurationForm {
@DDMFormField(label = "%date", type = "date")
public String date();
@DDMFormField(
label = "%select", optionLabels = {"%foo", "%bar"},
optionValues = {"foo", "bar"}, type = "select"
)
public String select();
@DDMFormField(label = "%text")
public String[] text();
@DDMFormField(label = "%rich-text", type = "rich_text")
public String richText();
}
3. Create a class that implements ConfigurationDDMFormDeclaration to
register your new configuration form class.
@Component(
property = "configurationPid=com.stockfish.configuration.CustomConfiguration",
service = ConfigurationDDMFormDeclaration.class
)
public class CustomConfigurationDDMFormDeclaration
implements ConfigurationDDMFormDeclaration {
@Override
public Class<?> getDDMFormClass() {
return CustomConfigurationForm .class;
}
}
You can find the above created Liferay Configuration Form under System
Settings -> Stockfish and it looks like this :
You can also add fields like uploading images and documents, selecting
colors, setting passwords for security, choosing web content from a
predefined list, and many more.
Same way, you can also use Liferay Configuration Form as site settings and
instance settings as well. .
This is how we can customize Liferay Configuration using Dynamic Data Mapping
(DDM) Form annotations: By leveraging DDM Form annotations in Liferay,
developers can create custom configurations for their applications. These
annotations allow for the easy creation of configuration forms with fields
tailored to specific requirements.
For comprehensive business solutions and in-depth insights into Create
Liferay Config Form using DDM Annotations, connect with us at info@stockfish.app to unlock the
full potential of your digital platform.